Bug #67269 [Com]: Adding DateInterval to a DateTime object does not add the correct amount
| From: | sea128 at post dot cz | Date: | Sat, 24 May 2014 15:25:03 +0000 |
| Subject: | Bug #67269 [Com]: Adding DateInterval to a DateTime object does not add the correct amount | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185917@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67269&edit=1
ID: 67269
Comment by: sea128 at post dot cz
Reported by: kai dot xu at achievers dot com
Summary: Adding DateInterval to a DateTime object does not
add the correct amount
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 5.4.27
Block user comment: N
Private report: N
New Comment:
Caused by daylight saving.
Similar to https://bugs.php.net/bug.php?id=63442
Previous Comments:
------------------------------------------------------------------------
[2014-05-20 18:36:41] kai dot xu at achievers dot com
The timezone setting is America/New_York
------------------------------------------------------------------------
[2014-05-13 17:38:05] kai dot xu at achievers dot com
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 this bug report at https://bugs.php.net/bug.php?id=67269&edit=1