Bug #69943 [Opn->Asn]: DateTime::add() and sub() doesn't account for TZ transitions
| From: | derick@php.net | Date: | Fri, 26 Jun 2015 21:50:50 +0000 |
| Subject: | Bug #69943 [Opn->Asn]: DateTime::add() and sub() doesn't account for TZ transitions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193930@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69943&edit=1
ID: 69943
Updated by: derick@php.net
Reported by: kernins at gmail dot com
Summary: DateTime::add() and sub() doesn't account for TZ
transitions
-Status: Open
+Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 5.6.10
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
New Comment:
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).
Previous Comments:
------------------------------------------------------------------------
[2015-06-26 16:58:21] 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 16:55:32] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69943&edit=1