php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74173 DateTimeImmutable::getTimestamp() triggers DST switch in incorrect time
Submitted: 2017-02-27 10:53 UTC Modified: 2021-04-06 19:54 UTC
Votes:4
Avg. Score:3.8 ± 1.3
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: mailtomuller at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.6.30 OS: Debian
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mailtomuller at gmail dot com
New email:
PHP Version: OS:

 

 [2017-02-27 10:53 UTC] mailtomuller at gmail dot com
Description:
------------
All PHP versions affected: 5.6.0 - 5.6.30, 7.0.0 - 7.1.2

- create DateTimeImmutable in UTC, hour before the actual DST switch
- change its timezone to Europe/Prague that observes DST
- absolute date/time stays the same, UTC offset is correctly changed
- call getTimeZone() on the instance
- the offset moves as if it went past the DST switch

Might be related to https://bugs.php.net/bug.php?id=65502

Online test script: https://3v4l.org/pQaKo

Expected:

2016-10-30T02:00:00+02:00
2016-10-30T02:00:00+02:00

Actual:

2016-10-30T02:00:00+02:00
2016-10-30T02:00:00+01:00


Test script:
---------------
<?php

$utc = new \DateTimeImmutable('2016-10-30T00:00:00+00:0');
// reproduces too:
// $utc = new \DateTimeImmutable('2016-10-30T00:00:00', new \DateTimeZone('UTC'));
// $utc = new \DateTimeImmutable('2016-10-30T00:00:00+00:0');

$prg = $utc->setTimeZone(new \DateTimeZone('Europe/Prague'));
echo $prg->format('c') . "\n";
$prg->getTimestamp();
echo $prg->format('c') . "\n";

Expected result:
----------------
2016-10-30T02:00:00+02:00
2016-10-30T02:00:00+02:00


Actual result:
--------------
2016-10-30T02:00:00+02:00
2016-10-30T02:00:00+01:00


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-27 10:55 UTC] mailtomuller at gmail dot com
step #4 in the description should be call getTimestamp(), not getTimeZone()
 [2017-02-27 11:27 UTC] derick@php.net
-Assigned To: +Assigned To: derick
 [2017-02-27 14:56 UTC] mailtomuller at gmail dot com
The possibly related bug is https://bugs.php.net/bug.php?id=67634 , I crosspasted the links.
 [2021-04-06 19:54 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2021-04-06 19:54 UTC] derick@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 8.1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC