php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kernins at gmail dot com
New email:
PHP Version: OS:

 

 [2015-06-26 16:55 UTC] kernins at gmail dot com
Description:
------------
See the snippet http://3v4l.org/YgUIV
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:
--------------
http://3v4l.org/YgUIV

diff=2
2014-10-26T02:59:59+0300
2014-10-25T23:59:59+0400

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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)

int(1) 
string(24) "2014-10-26T02:59:59+0300" 
string(24) "2014-10-25T23:59:59+0400"
 [2015-06-26 21:50 UTC] derick@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2015-06-26 21:50 UTC] derick@php.net
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] heiglandreas@php.net
That looks very much like a DST-Traversal issue to me. Therefore we're now tracking this in https://bugs.php.net/bug.php?id=74274
 [2017-03-19 11:48 UTC] heiglandreas@php.net
-Status: Assigned +Status: Duplicate
 [2017-03-19 11:48 UTC] heiglandreas@php.net
See before comment
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC