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: 2017-02-27 11:27 UTC
Votes:2
Avg. Score:2.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mailtomuller at gmail dot com Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 5.6.30 OS: Debian
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC