derick          Tue Jul  8 20:25:42 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/date/tests     test-parse-from-format.phpt 

  Modified files:              
    /php-src/ext/date/lib       parse_date.c parse_date.re 
  Log:
  - MFH: 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.29.2.30.2.14.2.17&r2=1.29.2.30.2.14.2.18&diff_format=u
Index: php-src/ext/date/lib/parse_date.c
diff -u php-src/ext/date/lib/parse_date.c:1.29.2.30.2.14.2.17 
php-src/ext/date/lib/parse_date.c:1.29.2.30.2.14.2.18
--- php-src/ext/date/lib/parse_date.c:1.29.2.30.2.14.2.17       Tue Jul  8 
18:28:29 2008
+++ php-src/ext/date/lib/parse_date.c   Tue Jul  8 20:25:09 2008
@@ -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"
 /*
    +----------------------------------------------------------------------+
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_date.c,v 1.29.2.30.2.14.2.17 2008/07/08 18:28:29 derick Exp $ */
+/* $Id: parse_date.c,v 1.29.2.30.2.14.2.18 2008/07/08 20:25:09 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.26.2.27.2.12.2.15&r2=1.26.2.27.2.12.2.16&diff_format=u
Index: php-src/ext/date/lib/parse_date.re
diff -u php-src/ext/date/lib/parse_date.re:1.26.2.27.2.12.2.15 
php-src/ext/date/lib/parse_date.re:1.26.2.27.2.12.2.16
--- php-src/ext/date/lib/parse_date.re:1.26.2.27.2.12.2.15      Tue Jul  8 
18:28:49 2008
+++ php-src/ext/date/lib/parse_date.re  Tue Jul  8 20:25:28 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: parse_date.re,v 1.26.2.27.2.12.2.15 2008/07/08 18:28:49 derick Exp $ */
+/* $Id: parse_date.re,v 1.26.2.27.2.12.2.16 2008/07/08 20:25:28 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

Reply via email to