-
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
DateTime diff returns wrong sign on day count when using a timezone (Regression) #9880
Comments
Indeed, this look completely wrong. |
This might be a duplicate of #9866. |
Similar difference in |
<?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);
?> php >= 8.1.10
php all php < 8.1.10
if uncomment $dateDiff php < 8.1.10
@cmb69 it's great bug exists for function diff (don't only duplicate) I am for restoring before creating same type timezone of php 8.1.10, adding a note in the manual for this use case otherwise the code needs improvement and I mean if different from same type it uses the same hacks that would be used with timezone type 3 Europe/Rome == Europe/Rome ... it is difficult to rewrite same type for this type of use. |
…phpGH-9700 (greedy tzid parsing)
Now fixed, for PHP 8.1.14 and PHP 8.2.1. |
Description
The following code:
https://3v4l.org/7biFY
Resulted in this output:
But I expected this output instead:
This code works as expected prior to 8.1.10.
If you comment out the
$dateTime->setTimezone(new DateTimeZone('America/New_York'));
line, the code works as expected on all versions.PHP Version
PHP 8.1.12
Operating System
Alpine 3.16
The text was updated successfully, but these errors were encountered: