derick Fri, 17 Jun 2011 16:38:23 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=312235
Log: - Fixed bug where the DateTime object got changed while using date_diff(). Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/date/lib/interval.c A php/php-src/branches/PHP_5_3/ext/date/tests/date_diff1.phpt U php/php-src/branches/PHP_5_4/ext/date/lib/interval.c A php/php-src/branches/PHP_5_4/ext/date/tests/date_diff1.phpt U php/php-src/trunk/ext/date/lib/interval.c A php/php-src/trunk/ext/date/tests/date_diff1.phpt Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2011-06-17 16:33:54 UTC (rev 312234) +++ php/php-src/branches/PHP_5_3/NEWS 2011-06-17 16:38:23 UTC (rev 312235) @@ -2,6 +2,11 @@ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2011, PHP 5.3.7 +- DateTime extension: + . Fixed bug where the DateTime object got changed while using date_diff(). + (Derick) + + 16 Jun 2011, PHP 5.3.7 RC1 - Upgraded bundled SQLite to version 3.7.6.3. (Scott) - Upgraded bundled PCRE to version 8.12. (Scott) Modified: php/php-src/branches/PHP_5_3/ext/date/lib/interval.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/lib/interval.c 2011-06-17 16:33:54 UTC (rev 312234) +++ php/php-src/branches/PHP_5_3/ext/date/lib/interval.c 2011-06-17 16:38:23 UTC (rev 312235) @@ -25,6 +25,7 @@ timelib_rel_time *rt; timelib_time *swp; timelib_sll dst_h_corr = 0, dst_m_corr = 0; + timelib_time one_backup, two_backup; rt = timelib_rel_time_ctor(); rt->invert = 0; @@ -45,6 +46,10 @@ dst_m_corr = ((two->z - one->z) % 3600) / 60; } + /* Save old TZ info */ + memcpy(&one_backup, one, sizeof(one_backup)); + memcpy(&two_backup, two, sizeof(two_backup)); + timelib_apply_localtime(one, 0); timelib_apply_localtime(two, 0); @@ -58,8 +63,9 @@ timelib_do_rel_normalize(rt->invert ? one : two, rt); - timelib_apply_localtime(one, 1); - timelib_apply_localtime(two, 1); + /* Restore old TZ info */ + memcpy(one, &one_backup, sizeof(one_backup)); + memcpy(two, &two_backup, sizeof(two_backup)); return rt; } Added: php/php-src/branches/PHP_5_3/ext/date/tests/date_diff1.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/tests/date_diff1.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/date/tests/date_diff1.phpt 2011-06-17 16:38:23 UTC (rev 312235) @@ -0,0 +1,48 @@ +--TEST-- +Test for date_diff with timezone abbreviations. +--INI-- +date.timezone=Europe/London +--FILE-- +<?php +$start = new DateTime('2010-10-04 02:18:48 EDT'); +$end = new DateTime('2010-11-06 18:38:28 EDT'); +$int = $start->diff($end); +var_dump($start); +var_dump($end); +var_dump($int); +?> +--EXPECT-- +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2010-10-04 02:18:48" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "EDT" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2010-11-06 18:38:28" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "EDT" +} +object(DateInterval)#3 (8) { + ["y"]=> + int(0) + ["m"]=> + int(1) + ["d"]=> + int(2) + ["h"]=> + int(16) + ["i"]=> + int(19) + ["s"]=> + int(40) + ["invert"]=> + int(0) + ["days"]=> + int(33) +} Modified: php/php-src/branches/PHP_5_4/ext/date/lib/interval.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/date/lib/interval.c 2011-06-17 16:33:54 UTC (rev 312234) +++ php/php-src/branches/PHP_5_4/ext/date/lib/interval.c 2011-06-17 16:38:23 UTC (rev 312235) @@ -25,6 +25,7 @@ timelib_rel_time *rt; timelib_time *swp; timelib_sll dst_h_corr = 0, dst_m_corr = 0; + timelib_time one_backup, two_backup; rt = timelib_rel_time_ctor(); rt->invert = 0; @@ -45,6 +46,10 @@ dst_m_corr = ((two->z - one->z) % 3600) / 60; } + /* Save old TZ info */ + memcpy(&one_backup, one, sizeof(one_backup)); + memcpy(&two_backup, two, sizeof(two_backup)); + timelib_apply_localtime(one, 0); timelib_apply_localtime(two, 0); @@ -58,8 +63,9 @@ timelib_do_rel_normalize(rt->invert ? one : two, rt); - timelib_apply_localtime(one, 1); - timelib_apply_localtime(two, 1); + /* Restore old TZ info */ + memcpy(one, &one_backup, sizeof(one_backup)); + memcpy(two, &two_backup, sizeof(two_backup)); return rt; } Added: php/php-src/branches/PHP_5_4/ext/date/tests/date_diff1.phpt =================================================================== --- php/php-src/branches/PHP_5_4/ext/date/tests/date_diff1.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/date/tests/date_diff1.phpt 2011-06-17 16:38:23 UTC (rev 312235) @@ -0,0 +1,48 @@ +--TEST-- +Test for date_diff with timezone abbreviations. +--INI-- +date.timezone=Europe/London +--FILE-- +<?php +$start = new DateTime('2010-10-04 02:18:48 EDT'); +$end = new DateTime('2010-11-06 18:38:28 EDT'); +$int = $start->diff($end); +var_dump($start); +var_dump($end); +var_dump($int); +?> +--EXPECT-- +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2010-10-04 02:18:48" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "EDT" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2010-11-06 18:38:28" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "EDT" +} +object(DateInterval)#3 (8) { + ["y"]=> + int(0) + ["m"]=> + int(1) + ["d"]=> + int(2) + ["h"]=> + int(16) + ["i"]=> + int(19) + ["s"]=> + int(40) + ["invert"]=> + int(0) + ["days"]=> + int(33) +} Modified: php/php-src/trunk/ext/date/lib/interval.c =================================================================== --- php/php-src/trunk/ext/date/lib/interval.c 2011-06-17 16:33:54 UTC (rev 312234) +++ php/php-src/trunk/ext/date/lib/interval.c 2011-06-17 16:38:23 UTC (rev 312235) @@ -25,6 +25,7 @@ timelib_rel_time *rt; timelib_time *swp; timelib_sll dst_h_corr = 0, dst_m_corr = 0; + timelib_time one_backup, two_backup; rt = timelib_rel_time_ctor(); rt->invert = 0; @@ -45,6 +46,10 @@ dst_m_corr = ((two->z - one->z) % 3600) / 60; } + /* Save old TZ info */ + memcpy(&one_backup, one, sizeof(one_backup)); + memcpy(&two_backup, two, sizeof(two_backup)); + timelib_apply_localtime(one, 0); timelib_apply_localtime(two, 0); @@ -58,8 +63,9 @@ timelib_do_rel_normalize(rt->invert ? one : two, rt); - timelib_apply_localtime(one, 1); - timelib_apply_localtime(two, 1); + /* Restore old TZ info */ + memcpy(one, &one_backup, sizeof(one_backup)); + memcpy(two, &two_backup, sizeof(two_backup)); return rt; } Added: php/php-src/trunk/ext/date/tests/date_diff1.phpt =================================================================== --- php/php-src/trunk/ext/date/tests/date_diff1.phpt (rev 0) +++ php/php-src/trunk/ext/date/tests/date_diff1.phpt 2011-06-17 16:38:23 UTC (rev 312235) @@ -0,0 +1,48 @@ +--TEST-- +Test for date_diff with timezone abbreviations. +--INI-- +date.timezone=Europe/London +--FILE-- +<?php +$start = new DateTime('2010-10-04 02:18:48 EDT'); +$end = new DateTime('2010-11-06 18:38:28 EDT'); +$int = $start->diff($end); +var_dump($start); +var_dump($end); +var_dump($int); +?> +--EXPECT-- +object(DateTime)#1 (3) { + ["date"]=> + string(19) "2010-10-04 02:18:48" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "EDT" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2010-11-06 18:38:28" + ["timezone_type"]=> + int(2) + ["timezone"]=> + string(3) "EDT" +} +object(DateInterval)#3 (8) { + ["y"]=> + int(0) + ["m"]=> + int(1) + ["d"]=> + int(2) + ["h"]=> + int(16) + ["i"]=> + int(19) + ["s"]=> + int(40) + ["invert"]=> + int(0) + ["days"]=> + int(33) +}
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php