]> granicus.if.org Git - php/commitdiff
- Fixed bug #40778 (DateInterval::format("%a") is always zero when an interval
authorDerick Rethans <derick@php.net>
Sun, 7 Mar 2010 15:26:39 +0000 (15:26 +0000)
committerDerick Rethans <derick@php.net>
Sun, 7 Mar 2010 15:26:39 +0000 (15:26 +0000)
  is created from an ISO string).

NEWS
ext/date/lib/parse_iso_intervals.c
ext/date/lib/parse_iso_intervals.re
ext/date/php_date.c
ext/date/tests/bug49778.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 09a92defcd89d164c20efb68f328b129e4e8b14c..8cdfc87e2a829481a2cc43b36e5592467ead6feb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,8 @@ PHP                                                                        NEWS
 - Fixed bug #50383 (Exceptions thrown in __call / __callStatic do not include
   file and line in trace). (Felipe)
 - Fixed bug #50358 (Compile failure compiling ext/phar/util.lo). (Felipe)
+- Fixed bug #49778 (DateInterval::format("%a") is always zero when an interval
+  is created from an ISO string). (Derick)
 
 
 ?? ??? 20??, PHP 5.3.2
index c63252f06fb89b9937332c0ebad093e9d878c7a3..cc58f1dc60be779841ac73cef9b088d49d18a20e 100644 (file)
@@ -1,10 +1,10 @@
-/* Generated by re2c 0.13.5 on Tue May  5 09:42:15 2009 */
+/* Generated by re2c 0.13.5 on Sun Mar  7 14:12:01 2010 */
 #line 1 "ext/date/lib/parse_iso_intervals.re"
 /*
    +----------------------------------------------------------------------+
    | PHP Version 5                                                        |
    +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2006 The PHP Group                                |
+   | Copyright (c) 1997-2010 The PHP Group                                |
    +----------------------------------------------------------------------+
    | This source file is subject to version 3.01 of the PHP license,      |
    | that is bundled with this package in the file LICENSE, and is        |
@@ -1118,6 +1118,7 @@ void timelib_strtointerval(char *s, int len,
        in.period->weekday = 0;
        in.period->weekday_behavior = 0;
        in.period->first_last_day_of = 0;
+       in.period->days = TIMELIB_UNSET;
 
        in.recurrences = 1;
 
index 670d5f2aba5edca4d5becb292dad2f48f5c46e4d..eb861a1a6b3a5ba0b70440c07e043f2c0cce86f0 100644 (file)
@@ -512,6 +512,7 @@ void timelib_strtointerval(char *s, int len,
        in.period->weekday = 0;
        in.period->weekday_behavior = 0;
        in.period->first_last_day_of = 0;
+       in.period->days = TIMELIB_UNSET;
 
        in.recurrences = 1;
 
index 519b796c876c53849a2a595254277ab4b9638b64..afd09cd5d4611839ac29e24bc3fa2338c5768fed 100644 (file)
@@ -2240,7 +2240,13 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
        PHP_DATE_INTERVAL_ADD_PROPERTY("i", i);
        PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
        PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
-       PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+       if (intervalobj->diff->days != -99999) {
+               PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+       } else {
+               MAKE_STD_ZVAL(zv);
+               ZVAL_FALSE(zv);
+               zend_hash_update(props, "days", 5, &zv, sizeof(zval), NULL);
+       }
 
        return props;
 }
@@ -3598,7 +3604,13 @@ static char *date_interval_format(char *format, int format_len, timelib_rel_time
                                case 'S': length = slprintf(buffer, 32, "%02d", (int) t->s); break;
                                case 's': length = slprintf(buffer, 32, "%d", (int) t->s); break;
 
-                               case 'a': length = slprintf(buffer, 32, "%d", (int) t->days); break;
+                               case 'a': {
+                                       if ((int) t->days != -99999) {
+                                               length = slprintf(buffer, 32, "%d", (int) t->days);
+                                       } else {
+                                               length = slprintf(buffer, 32, "(unknown)");
+                                       }
+                               } break;
                                case 'r': length = slprintf(buffer, 32, "%s", t->invert ? "-" : ""); break;
                                case 'R': length = slprintf(buffer, 32, "%c", t->invert ? '-' : '+'); break;
 
diff --git a/ext/date/tests/bug49778.phpt b/ext/date/tests/bug49778.phpt
new file mode 100644 (file)
index 0000000..67c8e27
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #49778 (DateInterval::format("%a") is always zero when an interval is created from an ISO string)
+--FILE--
+<?php
+$i=new DateInterval('P7D');
+var_dump($i);
+echo $i->format("%d"), "\n";
+echo $i->format("%a"), "\n";
+?>
+--EXPECT--
+object(DateInterval)#1 (8) {
+  ["y"]=>
+  int(0)
+  ["m"]=>
+  int(0)
+  ["d"]=>
+  int(7)
+  ["h"]=>
+  int(0)
+  ["i"]=>
+  int(0)
+  ["s"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  bool(false)
+}
+7
+(unknown)