php-src
php-src copied to clipboard
Adding a DateInterval during switch to DST can result in incorrect times
Description
Behaviour in PHP 8.1 is correct, but incorrect for PHP 8.0.17: https://3v4l.org/HQmqn
The following code:
<?php
date_default_timezone_set('Europe/Amsterdam');
$baseDate = new DateTimeImmutable('2022-03-27 01:30:00');
echo $baseDate->add(new DateInterval('PT1H'))->format('Y-m-d H:i:s') . PHP_EOL;
echo $baseDate->add(new DateInterval('PT2H'))->format('Y-m-d H:i:s') . PHP_EOL;
echo $baseDate->add(new DateInterval('PT1H'))->add(new DateInterval('PT1H'))->format('Y-m-d H:i:s') . PHP_EOL;
Resulted in this output:
2022-03-27 03:30:00
2022-03-27 03:30:00
2022-03-27 04:30:00
But I expected this output instead:
2022-03-27 03:30:00
2022-03-27 04:30:00
2022-03-27 04:30:00
PHP Version
PHP 8.0.17
Operating System
No response
Interesting: https://3v4l.org/AoXgT
Fixed from @derickr PHP >= 8.1 https://bugs.php.net/bug.php?id=75167
This is not something we can easily back port, so I am going to have to close this.