Bug #68503 [Opn->Csd]: date_diff on two dates with timezone set localised returns wrong results

From: Date: Tue, 06 Apr 2021 19:52:57 +0000
Subject: Bug #68503 [Opn->Csd]: date_diff on two dates with timezone set localised returns wrong results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233252@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68503&edit=1 ID: 68503 Updated by: derick@php.net Reported by: chris at vostron dot com Summary: date_diff on two dates with timezone set localised returns wrong results -Status: Open +Status: Closed Type: Bug Package: Date/time related Operating System: Ubuntu Trusty PHP Version: 5.6.3 -Assigned To: +Assigned To: derick Block user comment: N Private report: N New Comment: The fix for this bug has been committed. If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test. Thank you for the report, and for helping us make PHP better. Fixed for PHP 8.1. Previous Comments: ------------------------------------------------------------------------ [2014-11-26 10:36:09] chris at vostron dot com Description: ------------ When using date_diff in a localised time zone and the date_diff will traverse a daylight saving boundary, the number of days returned is 1 fewer than expected. This is understandable given the missing hour. However, it doesn't then set the "h" value to 23, which would be expected. Other option is that if we're not going to compare hours/mins/seconds when only passed a date, it should return "m" of 3, "d" of 0 in the example script. Test script: --------------- date_default_timezone_set('Europe/London'); var_dump(date_diff(new DateTime("2015-02-01"), new DateTime("2015-05-01"))); date_default_timezone_set('UTC'); var_dump(date_diff(new DateTime("2015-02-01"), new DateTime("2015-05-01"))); Expected result: ---------------- object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(3) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(89) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } object(DateInterval)#2 (15) { ["y"]=> int(0) ["m"]=> int(3) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(89) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } -- OR -- object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(2) ["d"]=> int(30) ["h"]=> int(23) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(89) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } object(DateInterval)#2 (15) { ["y"]=> int(0) ["m"]=> int(3) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(89) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } Actual result: -------------- object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(2) ["d"]=> int(30) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(89) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } object(DateInterval)#2 (15) { ["y"]=> int(0) ["m"]=> int(3) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(89) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68503&edit=1

« previous php.bugs (#233252) next »