Skip to content

PHP 8.1 Timezone doesn't work as intended #8108

Closed

Description

@Lenny4

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

Activity

  1. changed the title [-]PHP 8 Timezone doesn't work as intended[/-] [+]PHP 8 1 Timezone doesn't work as intended[/+] on Feb 17, 2022
  2. changed the title [-]PHP 8 1 Timezone doesn't work as intended[/-] [+]PHP 8.1 Timezone doesn't work as intended[/+] on Feb 17, 2022
  3. heiglandreas commented on Feb 17, 2022

    @heiglandreas
    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

  4. iluuu1994 commented on Feb 17, 2022

    @iluuu1994
    Member

    Related to #7752.

  5. self-assigned this
    on Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions