[php-src] Issue #9866: Bug introduced in PHP 8.

From: Date: Tue, 01 Nov 2022 15:06:46 +0000
Subject: [php-src] Issue #9866: Bug introduced in PHP 8.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242723@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9866 Author: jack-worman ### Description The following code: ```php <?php function getYearsBetween( \DateTimeImmutable $startDate, \DateTimeImmutable $endDate, ): int { $dateInterval = $startDate->diff($endDate, true); return $dateInterval->y; } $start = new \DateTimeImmutable('2000-11-01 09:29:22.907606', new \DateTimeZone('America/Chicago')); $end = new \DateTimeImmutable('2022-06-06 11:00:00.000000', new \DateTimeZone('America/New_York')); $result = getYearsBetween($start, $end); var_export($result); ``` Resulted in this output: ``` -22 ``` But I expected this output instead: ``` 21 ``` There seems to be a timezone issue that breaks \DateIntervals Works: https://3v4l.org/9KCZE Does not work: https://3v4l.org/nmPAj In the mean time, I will be ensuring both \DateTimeImmutables are in the same timezone before calling ->diff() ### PHP Version >= PHP 8.1.10 ### Operating System _No response_

« previous php.bugs (#242723) next »