php.net |  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
Description:
------------
Checked on PHP 7.0.14-2+deb.sury.org~xenial+1, 7.0.8-0ubuntu0.16.04.3 and https://3v4l.org/

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:
---------------
https://gist.github.com/anonymous/4cdca5e99eb0e1003e04dc4b54c8958f

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-04 11:46 UTC] cmb@php.net
This issue might be related to this years leap second.
 [2017-01-11 04:58 UTC] krakjoe@php.net
-Assigned To: +Assigned To: derick
 [2017-01-11 04:58 UTC] krakjoe@php.net
Derick, assigning to you: Can you take a quick look at this please ?
 [2017-01-16 19:26 UTC] heiglandreas@php.net
For easier check: https://3v4l.org/6Zjq5
 [2017-01-16 19:48 UTC] heiglandreas@php.net
Against the leap-second theory speaks https://3v4l.org/hjFnN
 [2017-02-10 17:08 UTC] derick@php.net
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] derick@php.net
-Status: Assigned +Status: Closed
 [2017-02-12 20:20 UTC] derick@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC