|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77103 new DateTime('now') return incorrect timezone during DST transitions
Submitted: 2018-11-03 23:12 UTC Modified: -
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: tomas dot prochazka at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.2.11 OS: irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tomas dot prochazka at gmail dot com
New email:
PHP Version: OS:


 [2018-11-03 23:12 UTC] tomas dot prochazka at gmail dot com
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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-04 08:38 UTC] jfcalcerrada at yahoo dot es
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);


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"

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"
 [2019-04-04 08:39 UTC] jfcalcerrada at yahoo dot es
Sorry! Corrected the expected output

string(25) "2017-10-29T00:59:59+01:00"
string(25) "2017-10-29T01:00:00+01:00"
string(25) "2017-10-29T01:59:59+01:00"
string(25) "2017-10-29T01:00:00+00:00"
string(25) "2017-10-29T01:59:59+00:00"
 [2020-09-12 00:52 UTC] antonino dot spampinato86 at gmail dot com
Times between 2:00:00 am and 2:59:59 am do not exist during the Forward Transitions transition. Attempts to create such times should be rounded forward, like PHP currently does when trying to create February 29th on a non-leap year.
Bug setTimestamp transitions.
Use DateTime construct @.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 02:01:23 2020 UTC