You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Time zone bug with \DateTimeInterface::diff() #9866
The return value more specifically represents the clock-time interval to apply to the original object ($this or $originObject) to arrive at the $targetObject. This process is not always reversible.
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'));
?>
Activity
[-]Bug introduced in PHP 8.[/-][+]Time zone bug with \DateTimeInterface::diff()[/+]heiglandreas commentedon Nov 1, 2022
That looks like the documentation of the parameter
absoluteis a bit ... off?hormus commentedon Nov 4, 2022
Without absolute
Yes bug, DateTimeImmutable from php 5.5.0, diff from php 5.3.0 expected result is 21.
Expected result: (only php < 8.1.10)
Expected result $dateDiff = $test1->diff($test2): (only php < 8.1.10)
Fixed phpGH-9699, phpGH-9866, and phpGH-9880 (problems with diff); and …
derickr commentedon Nov 30, 2022
Now fixed, for PHP 8.1.14 and PHP 8.2.1.