From: Derick Rethans Date: Tue, 8 Jul 2008 20:23:38 +0000 (+0000) Subject: - Fixed bug #45459 (date_create_from_format() fails on DATE_RFC3339) by X-Git-Tag: BEFORE_HEAD_NS_CHANGE~1335 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b30cdcd5a7d7248a2d6dfa45fec3f881a2ab799f;p=php - Fixed bug #45459 (date_create_from_format() fails on DATE_RFC3339) by allowing a few more format specifiers in date_create_from_format() / date_parse_from_format(). --- diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index a2e9a185ab..6cbb923968 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.4 on Tue Jul 8 20:26:31 2008 */ +/* Generated by re2c 0.13.5 on Tue Jul 8 22:21:57 2008 */ #line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ @@ -637,7 +637,7 @@ static const timelib_relunit* timelib_lookup_relunit(char **ptr) char *begin = *ptr, *end; const timelib_relunit *tp, *value = NULL; - while (**ptr != '\0' && **ptr != ' ' && **ptr != '\t') { + while (**ptr != '\0' && **ptr != ' ' && **ptr != ',' && **ptr != '\t') { ++*ptr; } end = *ptr; @@ -23408,6 +23408,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim while (*fptr && *ptr) { begin = ptr; switch (*fptr) { + case 'D': /* three letter day */ + case 'l': /* full day */ + tmp = timelib_lookup_relunit((char **) &ptr); + if (!tmp) { + add_pbf_error(s, "A textual day could not be found", string, begin); + } else { + s->time->m = tmp; + } + break; case 'd': /* two digit day, with leading zero */ case 'j': /* two digit day, without leading zero */ TIMELIB_CHECK_NUMBER; @@ -23521,6 +23530,9 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim break; case 'e': /* timezone */ + case 'P': /* timezone */ + case 'T': /* timezone */ + case 'O': /* timezone */ { int tz_not_found; s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); @@ -23575,6 +23587,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim ++ptr; break; + case '\\': /* escaped char */ + *fptr++; + if (*ptr == *fptr) { + ++ptr; + } else { + add_pbf_error(s, "The escaped character could not be found", string, begin); + } + break; + case '*': /* random chars until a separator or number ([ \t.,:;/-0123456789]) */ timelib_eat_until_separator((char **) &ptr); break; diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 943a3ea8fe..157c12f7fd 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -635,7 +635,7 @@ static const timelib_relunit* timelib_lookup_relunit(char **ptr) char *begin = *ptr, *end; const timelib_relunit *tp, *value = NULL; - while (**ptr != '\0' && **ptr != ' ' && **ptr != '\t') { + while (**ptr != '\0' && **ptr != ' ' && **ptr != ',' && **ptr != '\t') { ++*ptr; } end = *ptr; @@ -1818,6 +1818,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim while (*fptr && *ptr) { begin = ptr; switch (*fptr) { + case 'D': /* three letter day */ + case 'l': /* full day */ + tmp = timelib_lookup_relunit((char **) &ptr); + if (!tmp) { + add_pbf_error(s, "A textual day could not be found", string, begin); + } else { + s->time->m = tmp; + } + break; case 'd': /* two digit day, with leading zero */ case 'j': /* two digit day, without leading zero */ TIMELIB_CHECK_NUMBER; @@ -1931,6 +1940,9 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim break; case 'e': /* timezone */ + case 'P': /* timezone */ + case 'T': /* timezone */ + case 'O': /* timezone */ { int tz_not_found; s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb); @@ -1985,6 +1997,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim ++ptr; break; + case '\\': /* escaped char */ + *fptr++; + if (*ptr == *fptr) { + ++ptr; + } else { + add_pbf_error(s, "The escaped character could not be found", string, begin); + } + break; + case '*': /* random chars until a separator or number ([ \t.,:;/-0123456789]) */ timelib_eat_until_separator((char **) &ptr); break; diff --git a/ext/date/tests/test-parse-from-format.phpt b/ext/date/tests/test-parse-from-format.phpt new file mode 100644 index 0000000000..991a3b1a4c --- /dev/null +++ b/ext/date/tests/test-parse-from-format.phpt @@ -0,0 +1,144 @@ +--TEST-- +date_create_from_format() and date_parse_from_format(). +--INI-- +date.timezone=Europe/Oslo +--FILE-- +format( $format ) ; + $date2 = date_create_from_format( $format, $formatted ); + var_dump( $format, $formatted, $date2 ); + echo "\n"; + if ( $date2 === false ) + { + var_dump(date_parse_from_format( $format, $formatted ) ); + } +} +?> +--EXPECT-- +string(13) "Y-m-d\TH:i:sP" +string(25) "2008-07-08T22:14:12+02:00" +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "l, d-M-y H:i:s T" +string(36) "Tuesday, 08-Jul-08 22:14:12 GMT+0200" +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(13) "Y-m-d\TH:i:sO" +string(24) "2008-07-08T22:14:12+0200" +object(DateTime)#3 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "D, d M y H:i:s O" +string(29) "Tue, 08 Jul 08 22:14:12 +0200" +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "l, d-M-y H:i:s T" +string(36) "Tuesday, 08-Jul-08 22:14:12 GMT+0200" +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "D, d M y H:i:s O" +string(29) "Tue, 08 Jul 08 22:14:12 +0200" +object(DateTime)#3 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "D, d M Y H:i:s O" +string(31) "Tue, 08 Jul 2008 22:14:12 +0200" +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "D, d M Y H:i:s O" +string(31) "Tue, 08 Jul 2008 22:14:12 +0200" +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(13) "Y-m-d\TH:i:sP" +string(25) "2008-07-08T22:14:12+02:00" +object(DateTime)#3 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(16) "D, d M Y H:i:s O" +string(31) "Tue, 08 Jul 2008 22:14:12 +0200" +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +} + +string(13) "Y-m-d\TH:i:sP" +string(25) "2008-07-08T22:14:12+02:00" +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2008-07-08 22:14:12" + ["timezone_type"]=> + int(1) + ["timezone"]=> + string(6) "+02:00" +}