|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69943 DateTime::add() and sub() doesn't account for TZ transitions
Submitted: 2015-06-26 16:55 UTC Modified: 2017-03-19 11:48 UTC
From: kernins at gmail dot com Assigned: derick (profile)
Status: Duplicate Package: Date/time related
PHP Version: 5.6.10 OS: Linux
Private report: No CVE-ID: None
 [2015-06-26 16:55 UTC] kernins at gmail dot com
See the snippet
diff() behaves correctly, but add/sub - not.

PHP 5.4.34-5.4.42 and 5.5.18-5.6.10 are affected
As for older versions showing 1 hour difference - does php use its own bundled tzdata instead of system one? It may explain

The dates in example are around latest Europe/Moscow transition from +04:00 to +03:00 happened at 2014-10-25T22:00:00 UTC (01:59:59+04:00 + 1sec -> 01:00:00+03:00)

Test script:
$tz=new DateTimeZone('Europe/Moscow');
$d1=new DateTime('2014-10-26T00:59:59', $tz);
$d2=new DateTime('2014-10-26T01:59:59', $tz);

var_dump($d2->diff($d1, true)->h);
var_dump($d1->add($int=new DateInterval('PT2H'))->format(DateTime::ISO8601), $d2->sub($int)->format(DateTime::ISO8601));

Expected result:
Consistent add/sub results assuming 2hrs difference between test dates

2014-10-26T01:59:59+0300 for add()
2014-10-26T00:59:59+0400 for sub()

Actual result:



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-26 16:58 UTC] kernins at gmail dot com
Also 5.3.0 - 5.3.6 results looks interesting (note the diff() result and offsets)

string(24) "2014-10-26T02:59:59+0300" 
string(24) "2014-10-25T23:59:59+0400"
 [2015-06-26 21:50 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2015-06-26 21:50 UTC]
There are a few issues, but I would also like to point out that PHP does use its own bundled database. You can update it with the timezonedb PECL extension (except for the last two versions due to compatibility issues).
 [2015-06-27 08:56 UTC] kernins at gmail dot com
>You can update it with the timezonedb PECL extension
Thanks for the info
 [2017-03-19 11:48 UTC]
That looks very much like a DST-Traversal issue to me. Therefore we're now tracking this in
 [2017-03-19 11:48 UTC]
-Status: Assigned +Status: Duplicate
 [2017-03-19 11:48 UTC]
See before comment
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 08 22:01:23 2021 UTC