Bug #77103 [Opn->Csd]: new DateTime('now') return incorrect timezone during DST transitions
| From: | derick@php.net | Date: | Thu, 09 Jun 2022 10:23:31 +0000 |
| Subject: | Bug #77103 [Opn->Csd]: new DateTime('now') return incorrect timezone during DST transitions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241692@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77103&edit=1
ID: 77103
Updated by: derick@php.net
Reported by: tomas dot prochazka at gmail dot com
Summary: new DateTime('now') return incorrect timezone during
DST transitions
-Status: Open
+Status: Closed
Type: Bug
Package: Date/time related
Operating System: irrelevant
PHP Version: 7.2.11
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2020-09-12 00:52:25] 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
------------------------------------------------------------------------
[2019-04-04 08:39:09] 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"
------------------------------------------------------------------------
[2019-04-04 08:38:18] 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"
------------------------------------------------------------------------
[2018-11-03 23:12:24] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77103&edit=1