Bug #77103 [NEW]: new DateTime('now') return incorrect timezone during DST transitions
| From: | tomas dot prochazka at gmail dot com | Date: | Sat, 03 Nov 2018 23:12:24 +0000 |
| Subject: | Bug #77103 [NEW]: new DateTime('now') return incorrect timezone during DST transitions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-217810@lists.php.net to get a copy of this message | ||
From: tomas dot prochazka at gmail dot com
Operating system: irrelevant
PHP version: 7.2.11
Package: Date/time related
Bug Type: Bug
Bug description:new DateTime('now') return incorrect timezone during DST transitions
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 bug report at https://bugs.php.net/bug.php?id=77103&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77103&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77103&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77103&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77103&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77103&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77103&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77103&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77103&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77103&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77103&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77103&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77103&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77103&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77103&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77103&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77103&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77103&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77103&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77103&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77103&r=mysqlcfg