]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #45459 (date_create_from_format() fails on DATE_RFC3339) by
authorDerick Rethans <derick@php.net>
Tue, 8 Jul 2008 20:25:28 +0000 (20:25 +0000)
committerDerick Rethans <derick@php.net>
Tue, 8 Jul 2008 20:25:28 +0000 (20:25 +0000)
  allowing a few more format specifiers in date_create_from_format() /
  date_parse_from_format().

ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/tests/test-parse-from-format.phpt [new file with mode: 0644]

index 70fc36715824902dbbae4f41925ef23470e103df..558bda52f69999e258f80a2680b5717478752d7a 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.4 on Tue Jul  8 20:14:39 2008 */
+/* Generated by re2c 0.13.5 on Tue Jul  8 22:24:37 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;
index 943a3ea8fe7d00e729c20315c91d4809b29a7cc4..157c12f7fd969bb511ca636a68335c935b6d4b3d 100644 (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;
diff --git a/ext/date/tests/test-parse-from-format.phpt b/ext/date/tests/test-parse-from-format.phpt
new file mode 100644 (file)
index 0000000..991a3b1
--- /dev/null
@@ -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"
+}