php.net |  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: 2022-06-09 10:23 UTC
Votes:1
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: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.2.11 OS: irrelevant
Private report: No CVE-ID: None
 [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







Patches

Pull Requests

History

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);

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

Expected:
---------
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.
https://wiki.php.net/rfc/datetime_and_daylight_saving_time
Bug setTimestamp transitions.
Use DateTime construct @.
https://3v4l.org/CNGnE
 [2022-06-09 10:23 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2022-06-09 10:23 UTC] derick@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php

This was fixed in PHP 8.1.7:

https://3v4l.org/2ELVj
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC