Skip to content
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

PHP 8.1 Timezone doesn't work as intended #8108

Closed
Lenny4 opened this issue Feb 17, 2022 · 2 comments
Closed

PHP 8.1 Timezone doesn't work as intended #8108

Lenny4 opened this issue Feb 17, 2022 · 2 comments

Comments

@Lenny4
Copy link

Lenny4 commented Feb 17, 2022

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

@Lenny4 Lenny4 changed the title PHP 8 Timezone doesn't work as intended PHP 8 1 Timezone doesn't work as intended Feb 17, 2022
@Lenny4 Lenny4 changed the title PHP 8 1 Timezone doesn't work as intended PHP 8.1 Timezone doesn't work as intended Feb 17, 2022
@heiglandreas
Copy link
Contributor

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

@iluuu1994
Copy link
Member

Related to #7752.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
@heiglandreas @derickr @iluuu1994 @cmb69 @damianwadley @Lenny4 and others