|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73858 diff() of two relative/described DateTimes is wrong
Submitted: 2017-01-04 09:54 UTC Modified: 2017-02-12 20:20 UTC
From: nd at pcmltd dot eu Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.0.14 OS: Ubuntu 16.04.1 LTS
Private report: No CVE-ID: None
 [2017-01-04 09:54 UTC] nd at pcmltd dot eu
Checked on PHP, 7.0.8-0ubuntu0.16.04.3 and

Note: This bug seems to effect all PHP versions but HHVM 3.13.2 isn't effected.

It seems that when creating a DateTime from a described string, the dates get handled incorrectly at some point. When using the values my test script it seems that the DateTimes are seen to be correct (when var_dump'd the values are correct) but when you call a method (in my test I'm calling diff but getTimestamp() also caused the issue in some way) the diff results are incorrect and the next var_dump shows the DateTime has been incorrectly adjusted.

In my case it seems that the diff is wrong because the DateTime object changes when calling diff(). My dates should be first of December to the 31st but the second var_dump will show the end date being the first of December as well.

If I partly describe the date I want in the string and use the modify() method to adjust by the "- 1 second" everything seems to work as expected. This implies that the "- 1 second" contributes to this bug but it's not the actual cause, something else must be going on internally.

Note: I did search for other issues and there are DateTime/diff related issues but none seems to exactly match this issue. They could be related but I just wanted to tell you what I've been able to find out and test.

Test script:

Expected result:
date_test.php:11:int 30
date_test.php:16:int 30
date_test.php:24:int 30
date_test.php:29:int 30
date_test.php:37:int 30
date_test.php:43:int 30

Actual result:
date_test.php:11:int 0
date_test.php:16:int 30
date_test.php:24:int 0
date_test.php:29:int 30
date_test.php:37:int 30
date_test.php:43:int 30


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-04 11:46 UTC]
This issue might be related to this years leap second.
 [2017-01-11 04:58 UTC]
-Assigned To: +Assigned To: derick
 [2017-01-11 04:58 UTC]
Derick, assigning to you: Can you take a quick look at this please ?
 [2017-01-16 19:26 UTC]
For easier check:
 [2017-01-16 19:48 UTC]
Against the leap-second theory speaks
 [2017-02-10 17:08 UTC]
I have a patch for timelib, but collecting a few more before I push out a new version of timelib to merge into PHP.
 [2017-02-12 20:20 UTC]
-Status: Assigned +Status: Closed
 [2017-02-12 20:20 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 04:01:30 2024 UTC