-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Time zone bug with \DateTimeInterface::diff() #9866
Comments
jack-worman
changed the title
Bug introduced in PHP 8.
Time zone bug with \DateTimeInterface::diff()
Nov 1, 2022
That looks like the documentation of the parameter |
Without absolute <?php
$start = new \DateTime('2000-11-01 09:29:22.907606', new \DateTimeZone('America/Chicago'));
$end = new \DateTime('2022-06-06 11:00:00.000000', new \DateTimeZone('America/New_York'));
$result = $start->diff($end);
var_export($result->y);
?> Yes bug, DateTimeImmutable from php 5.5.0, diff from php 5.3.0 expected result is 21. <?php
$utc = new \DateTimeZone('UTC');
$london = new \DateTimeZone('Europe/London');
$test1 = new \DateTime('2018-01-31', $utc);
$test2 = new \DateTime('2018-03-31 00:00:00', $london);
$dateDiff = $test2->diff($test1); // true absolute Should the interval be forced to be positive
//$dateDiff = $test1->diff($test2);
$bugs = array('y' => &$dateDiff->y, 'm' => &$dateDiff->m, 'd' => &$dateDiff->d, 'h' => &$dateDiff->h, 'invert' => &$dateDiff->invert, 'days' => &$dateDiff->days);
$test3 = new \DateTime('+2 month ' . $test1->format('Y-m-d\\TH:i:s\\Z'));
var_dump($test3->format('Y-m-d H:i:s +00:00'), $bugs, $dateDiff->format('%r%a'));
?> Expected result: (only php < 8.1.10)
Expected result $dateDiff = $test1->diff($test2): (only php < 8.1.10)
|
derickr
added a commit
to derickr/php-src
that referenced
this issue
Nov 30, 2022
…phpGH-9700 (greedy tzid parsing)
Now fixed, for PHP 8.1.14 and PHP 8.2.1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The following code:
Resulted in this output:
But I expected this output instead:
There seems to be a timezone issue that breaks
\DateInterval
sWorks (same time zones): https://3v4l.org/RK34h
Does not work (different time zones): https://3v4l.org/nmPAj
In the mean time, I will be ensuring both
\DateTimeImmutable
s are in the same timezone before calling->diff()
PHP Version
>= 8.1.10
Operating System
No response
The text was updated successfully, but these errors were encountered: