Bug #67269 [NEW]: Adding DateInterval to a DateTime object does not add the correct amount

From: Date: Tue, 13 May 2014 17:38:06 +0000
Subject: Bug #67269 [NEW]: Adding DateInterval to a DateTime object does not add the correct amount
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185807@lists.php.net to get a copy of this message
From: kai dot xu at achievers dot com Operating system: Linux PHP version: 5.4.28 Package: Date/time related Bug Type: Bug Bug description:Adding DateInterval to a DateTime object does not add the correct amount Description: ------------ When adding a DateInterval to a DateTime object, it adds unexpected amounts of seconds. For the following time frames, adding DateInterval doesn't work correctly (my PHP version 5.4.27) // PT1M – adding 1 minute. Expected timestamp differential : 60 seconds 1414907940 - 1414911539 ( 2014-11-02 05:59:00 - 2014-11-02 06:58:59 ) test script result: -3540 1414911540 - 1414911599 ( 2014-11-02 06:59:00 - 2014-11-02 06:59:59 ) test script result: -7140 1446357540 - 1446361139 ( 2015-11-01 05:59:00 - 2015-11-01 06:58:59 ) test script result: -3540 1446361140 - 1446361199 ( 2015-11-01 06:59:00 - 2015-11-01 06:59:59 ) test script result: -7140 ------------------------------------------------------------------------------- // PT1H - adding 1 hour. Expected timestamp differential : 3600 seconds 1414904400 - 1414907999 ( 2014-11-02 05:00:00 - 2014-11-02 05:59:59 ) test script result: 0 1414908000 - 1414911599 ( 2014-11-02 06:00:00 - 2014-11-02 06:59:59 ) test script result: -3600 1446354000 - 1446357599 ( 2015-11-01 05:00:00 - 2015-11-01 05:59:59 ) test script result: 0 1446357600 - 1446361199 ( 2015-11-01 06:00:00 - 2015-11-01 06:59:59 ) test script result: -3600 ------------------------------------------------------------------------------- // P1D - adding 1 day. Expected timestamp differential : 86400 seconds 1394265600 - 1394348399 ( 2014-03-08 08:00:00 - 2014-03-09 06:59:59 ) test script result: 82800 1414821600 - 1414907999 ( 2014-11-01 06:00:00 - 2014-11-02 05:59:59 ) test script result: 90000 1425715200 - 1425797999 ( 2015-03-07 08:00:00 - 2015-03-08 06:59:59 ) test script result: 82800 1446271200 - 1446357599 ( 2015-10-31 06:00:00 - 2015-11-01 05:59:59 ) test script result: 90000 ------------------------------------------------------------------------------- Test script: --------------- // e.g. adding 1 minute to a DateTime object. The difference should be 60 but it returns -3560. $ts = 1414907940; $d = date('Y-m-d H:i:s', $ts); $dt = new DateTime($d); $di = new DateInterval('PT1M'); $dt->add($di); echo ($dt->getTimestamp() - $ts); // expecting 60 Expected result: ---------------- add the correct minute/hour/day to a DateTime object for any DateTime object Actual result: -------------- For some time frames, it sometimes adds more, sometimes adds less number of seconds to a Datetime object. (see description) -- Edit bug report at https://bugs.php.net/bug.php?id=67269&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67269&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67269&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67269&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=67269&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=67269&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=67269&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=67269&r=needscript Try newer version: https://bugs.php.net/fix.php?id=67269&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=67269&r=support Expected behavior: https://bugs.php.net/fix.php?id=67269&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=67269&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=67269&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=67269&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67269&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=67269&r=dst IIS Stability: https://bugs.php.net/fix.php?id=67269&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=67269&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=67269&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=67269&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=67269&r=mysqlcfg

« previous php.bugs (#185807) next »