php-src
php-src copied to clipboard
PHP 8.1 Timezone doesn't work as intended
Description
PHP 8.1 Timezone doesn't work as intended. offset is wrong in PHP 8.1.
Resulted in this output:
PHP 8.0
$timezone = 'Europe/Paris';
$timestamp = (new \DateTime('2022-02-16 00:00:00'))->getTimestamp();
$result = (new \DateTimeZone($timezone))->getTransitions($timestamp, $timestamp);
// $result['offset'] = 3600
PHP 8.1
$timezone = 'Europe/Paris';
$timestamp = (new \DateTime('2022-02-16 00:00:00'))->getTimestamp();
$result = (new \DateTimeZone($timezone))->getTransitions($timestamp, $timestamp);
// $result['offset'] = 7200
But I expected this output instead:
PHP 8.0
$timezone = 'Europe/Paris';
$timestamp = (new \DateTime('2022-02-16 00:00:00'))->getTimestamp();
$result = (new \DateTimeZone($timezone))->getTransitions($timestamp, $timestamp);
// $result['offset'] = 3600
PHP 8.1
$timezone = 'Europe/Paris';
$timestamp = (new \DateTime('2022-02-16 00:00:00'))->getTimestamp();
$result = (new \DateTimeZone($timezone))->getTransitions($timestamp, $timestamp);
// $result['offset'] = 3600
PHP Version
8.1
Operating System
Ubuntu 20.04.3 LTS
If you want the offset for a specific point in time I'd recommend using DateTimeImmutable::getOffset() instead.
echo (new DateTimeImmutable('Europe/Paris'))->getOffset();
// 3600
https://3v4l.org/LXVYV
Much more concerning is to me, that PHP8.1 does not seem to return an array of Transitions at all any more.
Code:
$a = new DateTimeImmutable('2022-02-17T12:00:00 Europe/Paris');
$b = $a->add(new Dateinterval('P12M'));
var_Dump($a, $b, (new DateTimezone('Europe/Paris'))->getTransitions($a->getTimestamp(), $b->getTimestamp()));
expected Outcome: an array with three transitions actual Output in PHP8.1: An array with one entry.
See https://3v4l.org/FSAmO
Related to https://github.com/php/php-src/issues/7752.