]> granicus.if.org Git - php/commitdiff
- Fixed bug #45554 (Inconsistent behavior of the u format char).
authorDerick Rethans <derick@php.net>
Wed, 29 Jul 2009 15:34:59 +0000 (15:34 +0000)
committerDerick Rethans <derick@php.net>
Wed, 29 Jul 2009 15:34:59 +0000 (15:34 +0000)
ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/tests/bug45554.phpt [new file with mode: 0644]

index d0d64b63429542e99ae9abeef29da38f8bbad4b7..835e0298249a2fd461fb90e6e0e9fac7747f2afc 100644 (file)
@@ -1,8 +1,8 @@
-/* Generated by re2c 0.13.5 on Thu Dec 18 15:50:45 2008 */
+/* Generated by re2c 0.13.5 on Wed Jul 29 16:31:12 2009 */
 #line 1 "ext/date/lib/parse_date.re"
 /*
    +----------------------------------------------------------------------+
-   | PHP Version 6                                                        |
+   | PHP Version 5                                                        |
    +----------------------------------------------------------------------+
    | Copyright (c) 1997-2006 The PHP Group                                |
    +----------------------------------------------------------------------+
@@ -24086,10 +24086,18 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
                                        add_pbf_error(s, "A two digit second could not be found", string, begin);
                                }
                                break;
-                       case 'u': /* five digit millisecond, with leading zero */
-                               TIMELIB_CHECK_NUMBER;
-                               if ((s->time->f = timelib_get_nr((char **) &ptr, 5)) == TIMELIB_UNSET) {
-                                       add_pbf_error(s, "A five digit millisecond could not be found", string, begin);
+                       case 'u': /* six digit millisecond */
+                               {
+                                       double f;
+                                       char *tptr;
+
+                                       TIMELIB_CHECK_NUMBER;
+                                       tptr = ptr;
+                                       if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
+                                               add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
+                                       } else {
+                                               s->time->f = (f / 1000000);
+                                       }
                                }
                                break;
                        case ' ': /* any sort of whitespace (' ' and \t) */
index 049685dd4ab026124a63dccf83768b2ded50d140..2fadb7b92e5e259ede12d6b41e181279afb90187 100644 (file)
@@ -1943,10 +1943,18 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
                                        add_pbf_error(s, "A two digit second could not be found", string, begin);
                                }
                                break;
-                       case 'u': /* five digit millisecond, with leading zero */
-                               TIMELIB_CHECK_NUMBER;
-                               if ((s->time->f = timelib_get_nr((char **) &ptr, 5)) == TIMELIB_UNSET) {
-                                       add_pbf_error(s, "A five digit millisecond could not be found", string, begin);
+                       case 'u': /* six digit millisecond */
+                               {
+                                       double f;
+                                       char *tptr;
+
+                                       TIMELIB_CHECK_NUMBER;
+                                       tptr = ptr;
+                                       if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
+                                               add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
+                                       } else {
+                                               s->time->f = (f / 1000000);
+                                       }
                                }
                                break;
                        case ' ': /* any sort of whitespace (' ' and \t) */
diff --git a/ext/date/tests/bug45554.phpt b/ext/date/tests/bug45554.phpt
new file mode 100644 (file)
index 0000000..9416214
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #45554 (Inconsistent behavior of the u format char)
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$format = "m-d-Y H:i:s.u T";
+$d = date_create_from_format($format, "03-15-2005 12:22:29.000000 PST");
+echo $d->format($format), "\n";
+
+$d = date_create_from_format($format, "03-15-2005 12:22:29.001001 PST");
+echo $d->format($format), "\n";
+
+$d = date_create_from_format($format, "03-15-2005 12:22:29.0010 PST");
+var_dump( $d );
+?>
+--EXPECT--
+03-15-2005 12:22:29.000000 PST
+03-15-2005 12:22:29.001000 PST
+bool(false)