- 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().
This commit is contained in:
Derick Rethans 2008-07-08 20:23:38 +00:00
parent d5bc2d0682
commit b30cdcd5a7
3 changed files with 189 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,144 @@
--TEST--
date_create_from_format() and date_parse_from_format().
--INI--
date.timezone=Europe/Oslo
--FILE--
<?php
$formats = array( DATE_ATOM, DATE_COOKIE, DATE_ISO8601, DATE_RFC822,
DATE_RFC850, DATE_RFC1036, DATE_RFC1123, DATE_RFC2822, DATE_RFC3339,
DATE_RSS, DATE_W3C );
foreach( $formats as $format )
{
$date = new DateTime( "2008-07-08T22:14:12+02:00" );
$formatted = $date->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"
}