|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-04-21 22:00 UTC] kylekatarnls at gmail dot com
Description:
------------
In PHP < 8.1, comparing 2 date-times from different timezones would consider the real moment they represent to return the diff, which is completly relevant. But it's no longer true (sounds like introduced by 091c0920b9db057a54dc43ece6e864bce6818d5e).
Test script:
---------------
$dtToronto = new DateTime('2012-01-01 00:00:00.000000 America/Toronto');
$dtVancouver = new DateTime('2012-01-01 00:00:00.000000 America/Vancouver');
echo $dtVancouver->diff($dtToronto)->format('%h');
Expected result:
----------------
3
Actual result:
--------------
0
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
Hello, sorry derick but here the fix caused an other regression: Try the following code: ----------------------- <?php $d1 = new DateTimeImmutable('2014-07-08 15:20', new DateTimeZone('America/Toronto')); $d2 = $d1->modify('1 day'); var_dump($d1->setTimezone(new DateTimeZone('UTC'))->diff($d2)->days); var_dump($d1->diff($d2)->days); ----------------------- `days` is 1 for both in PHP < 8.1 => correct since $d2 is $d1 + 1 day and there is no DST there, so I expect to always get 1 with any timezone. `days` is 0 since 8.1.0beta3 => very likely a bug. Did you check my PR? https://github.com/derickr/timelib/pull/110/files