php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80974 Wrong diff between 2 dates in different timezones
Submitted: 2021-04-21 22:00 UTC Modified: 2021-08-17 13:40 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kylekatarnls at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: master-Git-2021-04-21 (Git) OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kylekatarnls at gmail dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-21 22:03 UTC] derick@php.net
-Assigned To: +Assigned To: derick
 [2021-04-22 09:50 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #80974: Wrong diff between 2 dates in different timezones
On GitHub:  https://github.com/php/php-src/pull/6896
Patch:      https://github.com/php/php-src/pull/6896.patch
 [2021-04-26 08:22 UTC] corey dot taylor dot fl at gmail dot com
I assume this is related since it was closed with the large patch from derick.

https://bugs.php.net/bug.php?id=79452
 [2021-08-08 12:42 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2021-08-08 12:42 UTC] derick@php.net
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.

For 8.1.0beta3
 [2021-08-16 19:37 UTC] kylekatarnls at gmail dot com
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
 [2021-08-17 13:14 UTC] derick@php.net
Kyle, your new "bug" is unrelated to the one that was reported here. The "days" property is not the same as formatting the "d" (representing days in a year/month/days kind of way), which with your test case are correct:
 [2021-08-17 13:40 UTC] kylekatarnls at gmail dot com
Is this bug tracked somewhere and planned to be fixed before stable release? It's not there in PHP <= 8.0 and I didn't noticed it neither before 8.1.0beta3.
 [2021-09-18 19:56 UTC] kylekatarnls at gmail dot com
I think the fix for this bug caused the following regression:
https://bugs.php.net/bug.php?id=81458
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 15:03:34 2021 UTC