From: Derick Rethans Date: Sun, 7 Mar 2010 15:26:39 +0000 (+0000) Subject: - Fixed bug #40778 (DateInterval::format("%a") is always zero when an interval X-Git-Tag: php-5.4.0alpha1~221 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=156d780cbd8ed839f6d1b14b082c80ad7c11cc6f;p=php - Fixed bug #40778 (DateInterval::format("%a") is always zero when an interval is created from an ISO string). --- diff --git a/NEWS b/NEWS index 09a92defcd..8cdfc87e2a 100644 --- 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 diff --git a/ext/date/lib/parse_iso_intervals.c b/ext/date/lib/parse_iso_intervals.c index c63252f06f..cc58f1dc60 100644 --- a/ext/date/lib/parse_iso_intervals.c +++ b/ext/date/lib/parse_iso_intervals.c @@ -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; diff --git a/ext/date/lib/parse_iso_intervals.re b/ext/date/lib/parse_iso_intervals.re index 670d5f2aba..eb861a1a6b 100644 --- a/ext/date/lib/parse_iso_intervals.re +++ b/ext/date/lib/parse_iso_intervals.re @@ -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; diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 519b796c87..afd09cd5d4 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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 index 0000000000..67c8e27f91 --- /dev/null +++ b/ext/date/tests/bug49778.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #49778 (DateInterval::format("%a") is always zero when an interval is created from an ISO string) +--FILE-- +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)