From: Derick Rethans Date: Wed, 15 Dec 2010 21:45:25 +0000 (+0000) Subject: - Fixed a bug in DateTime->modify() where absolute date/time statements had no X-Git-Tag: php-5.3.6RC1~215 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cf5713dd355f2b3b9270a61a975a8fcf4d17db6;p=php - Fixed a bug in DateTime->modify() where absolute date/time statements had no effect. --- diff --git a/NEWS b/NEWS index c38ccd0d81..4c67881f45 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,10 @@ . Fixed bug #48607 (fwrite() doesn't check reply from ftp server before exiting). (Ilia) +- DateTime extension: + . Fixed a bug in DateTime->modify() where absolute date/time statements had + no effect. (Derick) + - Filter extension: . Fixed bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges). (Ilia) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 568ba5a99e..57d721bc19 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2797,6 +2797,31 @@ PHP_FUNCTION(date_modify) memcpy(&dateobj->time->relative, &tmp_time->relative, sizeof(struct timelib_rel_time)); dateobj->time->have_relative = tmp_time->have_relative; dateobj->time->sse_uptodate = 0; + + if (tmp_time->y != -99999) { + dateobj->time->y = tmp_time->y; + } + if (tmp_time->m != -99999) { + dateobj->time->m = tmp_time->m; + } + if (tmp_time->d != -99999) { + dateobj->time->d = tmp_time->d; + } + + if (tmp_time->h != -99999) { + dateobj->time->h = tmp_time->h; + if (tmp_time->i != -99999) { + dateobj->time->i = tmp_time->i; + if (tmp_time->s != -99999) { + dateobj->time->s = tmp_time->s; + } else { + dateobj->time->s = 0; + } + } else { + dateobj->time->i = 0; + dateobj->time->s = 0; + } + } timelib_time_dtor(tmp_time); timelib_update_ts(dateobj->time, NULL); diff --git a/ext/date/tests/DateTime_modify_variation1.phpt b/ext/date/tests/DateTime_modify_variation1.phpt index 4d27071d04..faeb70cbd9 100644 --- a/ext/date/tests/DateTime_modify_variation1.phpt +++ b/ext/date/tests/DateTime_modify_variation1.phpt @@ -133,7 +133,7 @@ bool(false) -- float 10.5 -- object(DateTime)#3 (3) { ["date"]=> - string(19) "2009-01-31 14:28:41" + string(19) "2009-01-31 10:05:00" ["timezone_type"]=> int(3) ["timezone"]=> @@ -148,7 +148,7 @@ bool(false) -- float .5 -- object(DateTime)#3 (3) { ["date"]=> - string(19) "2009-01-31 14:28:41" + string(19) "2009-01-31 00:05:00" ["timezone_type"]=> int(3) ["timezone"]=> diff --git a/ext/date/tests/date-time-modify-times.phpt b/ext/date/tests/date-time-modify-times.phpt new file mode 100644 index 0000000000..258ddbd420 --- /dev/null +++ b/ext/date/tests/date-time-modify-times.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test for DateTime::modify() with absolute time statements +--INI-- +date.timezone=Europe/London +--FILE-- + array( + 'october 23:00', // October 23rd, with a broken time + 'back of 4pm', + 'next week monday', + 'next week monday 10am', + 'tuesday noon', + 'first monday of January 2011', + 'first monday of January 2011 09:00', + ), + '2010-12-15 19:42:45' => array( + 'october 23:00', // October 23rd, with a broken time + 'march 28, 00:15', + 'march 28, 01:15', // doesn't exist bcause of DST + 'march 28, 02:15', + ), +); + +foreach ( $tests as $start => $data ) +{ + foreach ( $data as $test ) + { + echo date_create( $start ) + ->modify( $test ) + ->format( DateTime::RFC2822 ), "\n"; + } +} +echo "\n"; +?> +--EXPECT-- +Sat, 23 Oct 2010 00:00:00 +0000 +Wed, 15 Dec 2010 16:15:00 +0000 +Mon, 20 Dec 2010 00:00:00 +0000 +Mon, 20 Dec 2010 10:00:00 +0000 +Tue, 21 Dec 2010 12:00:00 +0000 +Mon, 03 Jan 2011 00:00:00 +0000 +Mon, 03 Jan 2011 09:00:00 +0000 +Sat, 23 Oct 2010 00:00:00 +0100 +Sun, 28 Mar 2010 00:15:00 +0000 +Sun, 28 Mar 2010 02:15:00 +0100 +Sun, 28 Mar 2010 02:15:00 +0100 diff --git a/ext/date/tests/date_modify_variation2.phpt b/ext/date/tests/date_modify_variation2.phpt index 08db14cf89..fe6afb16dd 100644 --- a/ext/date/tests/date_modify_variation2.phpt +++ b/ext/date/tests/date_modify_variation2.phpt @@ -133,7 +133,7 @@ bool(false) -- float 10.5 -- object(DateTime)#%d (3) { ["date"]=> - string(19) "2009-01-31 14:28:41" + string(19) "2009-01-31 10:05:00" ["timezone_type"]=> int(3) ["timezone"]=> @@ -148,7 +148,7 @@ bool(false) -- float .5 -- object(DateTime)#%d (3) { ["date"]=> - string(19) "2009-01-31 14:28:41" + string(19) "2009-01-31 00:05:00" ["timezone_type"]=> int(3) ["timezone"]=>