From 923a5de072022dd5b38e0a68e503e7005745d146 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 29 Jul 2009 15:34:59 +0000 Subject: [PATCH] - Fixed bug #45554 (Inconsistent behavior of the u format char). --- ext/date/lib/parse_date.c | 20 ++++++++++++++------ ext/date/lib/parse_date.re | 16 ++++++++++++---- ext/date/tests/bug45554.phpt | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 ext/date/tests/bug45554.phpt diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index d0d64b6342..835e029824 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -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) */ diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 049685dd4a..2fadb7b92e 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -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 index 0000000000..9416214e93 --- /dev/null +++ b/ext/date/tests/bug45554.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #45554 (Inconsistent behavior of the u format char) +--INI-- +date.timezone=UTC +--FILE-- +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) -- 2.40.0