derick Wed, 15 Dec 2010 21:45:25 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=306392
Log: - Fixed a bug in DateTime->modify() where absolute date/time statements had no effect. Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/date/php_date.c U php/php-src/branches/PHP_5_3/ext/date/tests/DateTime_modify_variation1.phpt A php/php-src/branches/PHP_5_3/ext/date/tests/date-time-modify-times.phpt U php/php-src/branches/PHP_5_3/ext/date/tests/date_modify_variation2.phpt U php/php-src/trunk/ext/date/php_date.c U php/php-src/trunk/ext/date/tests/DateTime_modify_variation1.phpt A php/php-src/trunk/ext/date/tests/date-time-modify-times.phpt U php/php-src/trunk/ext/date/tests/date_modify_variation2.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/branches/PHP_5_3/NEWS 2010-12-15 21:45:25 UTC (rev 306392) @@ -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) Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/php_date.c 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/branches/PHP_5_3/ext/date/php_date.c 2010-12-15 21:45:25 UTC (rev 306392) @@ -2797,6 +2797,31 @@ 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); Modified: php/php-src/branches/PHP_5_3/ext/date/tests/DateTime_modify_variation1.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/tests/DateTime_modify_variation1.phpt 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/branches/PHP_5_3/ext/date/tests/DateTime_modify_variation1.phpt 2010-12-15 21:45:25 UTC (rev 306392) @@ -133,7 +133,7 @@ -- 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 @@ -- 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"]=> Added: php/php-src/branches/PHP_5_3/ext/date/tests/date-time-modify-times.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/tests/date-time-modify-times.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/date/tests/date-time-modify-times.phpt 2010-12-15 21:45:25 UTC (rev 306392) @@ -0,0 +1,47 @@ +--TEST-- +Test for DateTime::modify() with absolute time statements +--INI-- +date.timezone=Europe/London +--FILE-- +<?php +$tests = array( + '2010-12-15 19:42:45 UTC' => 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 Modified: php/php-src/branches/PHP_5_3/ext/date/tests/date_modify_variation2.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/tests/date_modify_variation2.phpt 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/branches/PHP_5_3/ext/date/tests/date_modify_variation2.phpt 2010-12-15 21:45:25 UTC (rev 306392) @@ -133,7 +133,7 @@ -- 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 @@ -- 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"]=> Modified: php/php-src/trunk/ext/date/php_date.c =================================================================== --- php/php-src/trunk/ext/date/php_date.c 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/trunk/ext/date/php_date.c 2010-12-15 21:45:25 UTC (rev 306392) @@ -2792,6 +2792,31 @@ 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); Modified: php/php-src/trunk/ext/date/tests/DateTime_modify_variation1.phpt =================================================================== --- php/php-src/trunk/ext/date/tests/DateTime_modify_variation1.phpt 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/trunk/ext/date/tests/DateTime_modify_variation1.phpt 2010-12-15 21:45:25 UTC (rev 306392) @@ -133,7 +133,7 @@ -- 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 @@ -- 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"]=> Added: php/php-src/trunk/ext/date/tests/date-time-modify-times.phpt =================================================================== --- php/php-src/trunk/ext/date/tests/date-time-modify-times.phpt (rev 0) +++ php/php-src/trunk/ext/date/tests/date-time-modify-times.phpt 2010-12-15 21:45:25 UTC (rev 306392) @@ -0,0 +1,47 @@ +--TEST-- +Test for DateTime::modify() with absolute time statements +--INI-- +date.timezone=Europe/London +--FILE-- +<?php +$tests = array( + '2010-12-15 19:42:45 UTC' => 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 Modified: php/php-src/trunk/ext/date/tests/date_modify_variation2.phpt =================================================================== --- php/php-src/trunk/ext/date/tests/date_modify_variation2.phpt 2010-12-15 21:42:42 UTC (rev 306391) +++ php/php-src/trunk/ext/date/tests/date_modify_variation2.phpt 2010-12-15 21:45:25 UTC (rev 306392) @@ -133,7 +133,7 @@ -- 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 @@ -- 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"]=>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php