Bug #69943 [NEW]: DateTime::add() and sub() doesn't account for TZ transitions
| From: | kernins at gmail dot com | Date: | Fri, 26 Jun 2015 16:55:32 +0000 |
| Subject: | Bug #69943 [NEW]: DateTime::add() and sub() doesn't account for TZ transitions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193918@lists.php.net to get a copy of this message | ||
From: kernins at gmail dot com
Operating system: Linux
PHP version: 5.6.10
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::add() and sub() doesn't account for TZ transitions
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 bug report at https://bugs.php.net/bug.php?id=69943&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69943&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69943&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69943&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69943&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69943&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69943&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69943&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69943&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69943&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69943&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69943&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69943&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69943&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69943&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69943&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69943&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69943&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69943&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69943&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69943&r=mysqlcfg