Bug #74173 [Opn]: DateTimeImmutable::getTimestamp() triggers DST switch in incorrect time

From: Date: Mon, 27 Feb 2017 10:55:39 +0000
Subject: Bug #74173 [Opn]: DateTimeImmutable::getTimestamp() triggers DST switch in incorrect time
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207575@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74173&edit=1

 ID:                 74173
 User updated by:    mailtomuller at gmail dot com
 Reported by:        mailtomuller at gmail dot com
 Summary:            DateTimeImmutable::getTimestamp() triggers DST
                     switch in incorrect time
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Debian
 PHP Version:        5.6.30
 Block user comment: N
 Private report:     N

 New Comment:

step #4 in the description should be call getTimestamp(), not getTimeZone()


Previous Comments:
------------------------------------------------------------------------
[2017-02-27 10:53:52] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74173&edit=1


Thread (4 messages)

« previous php.bugs (#207575) next »