|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-11-03 23:12 UTC] tomas dot prochazka at gmail dot com
Description:
------------
For timezone Europe/Prague should be DST changed at 2018-10-28 at 3 am back to 2 am.
Until 3 am. it still should be CEST time, and after change it should be CET.
So time between 2 and 3 is repeated two times, but in different timezone.
When I'm using this code before 2 am in the transition day 2018-10-28 it works as expected:
$d = DateTime('now')
$d->format('Y-m-d H:i:s P T') => 2018-10-28 01:58:38 +02:00 CEST
$d->$d->getOffset() => 7200
but few minutes later, after 2 am, the same code return
2018-10-28 02:00:04 +01:00 CET
3600
Which is not true, it still should be +02:00 CEST and 7200.
After 2:39:59 it correctly return back to 2:00:00 and now already correctly with CET.
So if you are logging data do some log file in the standardized format like $d->format(DateTime::ISO8601) you will get all times between 2 and 3 am twice the time with exactly the same time string. Which is really very wrong. I would not expect such bug in PHP.
Luckily date('P, Z, I, T') works correctly
It return "+02:00, 7200, 1, CEST" between 2 and 3 am before DST transition.
I found that I can use this
$d = new \Nette\Utils\DateTime(date('Y-m-d H:i:s T')); instead of 'now'
and then it correctly return
2018-10-28 02:12:03 +02:00 CEST
7200
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 04:00:01 2025 UTC |
There seems to be a problem when transitioning out of DST. Some times are duplicated, as the offset is not handled correctly: $tz = new DateTimeZone('Europe/London'); $date = new DateTimeImmutable('now', $tz); $time = 1509235200; $date1 = $date->setTimestamp($time - 1); $date2 = $date->setTimestamp($time); $date3 = $date->setTimestamp($time + 3600 - 1); $date4 = $date->setTimestamp($time + 3600); $date5 = $date->setTimestamp($time + 3600*2 - 1); var_dump($date1->format(DateTime::ATOM)); var_dump($date2->format(DateTime::ATOM)); var_dump($date3->format(DateTime::ATOM)); var_dump($date4->format(DateTime::ATOM)); var_dump($date5->format(DateTime::ATOM)); Expected: --------- string(25) "2017-10-29T00:59:59+01:00" string(25) "2017-10-29T01:00:00+00:00" string(25) "2017-10-29T01:59:59+00:00" string(25) "2017-10-29T01:00:00+00:00" string(25) "2017-10-29T01:59:59+00:00" Actual: ------- string(25) "2017-10-29T00:59:59+01:00" string(25) "2017-10-29T01:00:00+00:00" string(25) "2017-10-29T01:59:59+00:00" string(25) "2017-10-29T01:00:00+00:00" string(25) "2017-10-29T01:59:59+00:00"