From: Derick Rethans Date: Fri, 17 Jun 2011 16:38:23 +0000 (+0000) Subject: - Fixed bug where the DateTime object got changed while using date_diff(). X-Git-Tag: php-5.4.0alpha1~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9437d4cea4377934bcda99ad81d134cf119feea1;p=php - Fixed bug where the DateTime object got changed while using date_diff(). --- diff --git a/ext/date/lib/interval.c b/ext/date/lib/interval.c index 6ac07419b4..c8200a48c3 100644 --- a/ext/date/lib/interval.c +++ b/ext/date/lib/interval.c @@ -25,6 +25,7 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two) 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 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two) 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_rel_time *timelib_diff(timelib_time *one, timelib_time *two) 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; } diff --git a/ext/date/tests/date_diff1.phpt b/ext/date/tests/date_diff1.phpt new file mode 100644 index 0000000000..cf32fcbf3b --- /dev/null +++ b/ext/date/tests/date_diff1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test for date_diff with timezone abbreviations. +--INI-- +date.timezone=Europe/London +--FILE-- +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) +}