derick Tue Jul 8 20:23:39 2008 UTC
Added files:
/php-src/ext/date/tests test-parse-from-format.phpt
Modified files:
/php-src/ext/date/lib parse_date.c parse_date.re
Log:
- 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().
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_date.c?r1=1.90&r2=1.91&diff_format=u
Index: php-src/ext/date/lib/parse_date.c
diff -u php-src/ext/date/lib/parse_date.c:1.90
php-src/ext/date/lib/parse_date.c:1.91
--- php-src/ext/date/lib/parse_date.c:1.90 Tue Jul 8 18:27:06 2008
+++ php-src/ext/date/lib/parse_date.c Tue Jul 8 20:23:38 2008
@@ -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"
/*
+----------------------------------------------------------------------+
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: parse_date.c,v 1.90 2008/07/08 18:27:06 derick Exp $ */
+/* $Id: parse_date.c,v 1.91 2008/07/08 20:23:38 derick Exp $ */
#include "timelib.h"
@@ -637,7 +637,7 @@
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 @@
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 @@
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 @@
++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;
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_date.re?r1=1.81&r2=1.82&diff_format=u
Index: php-src/ext/date/lib/parse_date.re
diff -u php-src/ext/date/lib/parse_date.re:1.81
php-src/ext/date/lib/parse_date.re:1.82
--- php-src/ext/date/lib/parse_date.re:1.81 Tue Jul 8 18:27:07 2008
+++ php-src/ext/date/lib/parse_date.re Tue Jul 8 20:23:38 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: parse_date.re,v 1.81 2008/07/08 18:27:07 derick Exp $ */
+/* $Id: parse_date.re,v 1.82 2008/07/08 20:23:38 derick Exp $ */
#include "timelib.h"
@@ -635,7 +635,7 @@
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 @@
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 @@
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 @@
++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;
http://cvs.php.net/viewvc.cgi/php-src/ext/date/tests/test-parse-from-format.phpt?view=markup&rev=1.1
Index: php-src/ext/date/tests/test-parse-from-format.phpt
+++ php-src/ext/date/tests/test-parse-from-format.phpt
--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"
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php