Bug #73858 [Asn]: diff() of two relative/described DateTimes is wrong

From: Date: Fri, 10 Feb 2017 17:08:01 +0000
Subject: Bug #73858 [Asn]: diff() of two relative/described DateTimes is wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207255@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73858&edit=1

 ID:                 73858
 Updated by:         derick@php.net
 Reported by:        nd at pcmltd dot eu
 Summary:            diff() of two relative/described DateTimes is wrong
 Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 Operating System:   Ubuntu 16.04.1 LTS
 PHP Version:        7.0.14
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

I have a patch for timelib, but collecting a few more before I push out a new version of timelib to
merge into PHP.


Previous Comments:
------------------------------------------------------------------------
[2017-01-16 19:48:51] heiglandreas@php.net

Against the leap-second theory speaks https://3v4l.org/hjFnN

------------------------------------------------------------------------
[2017-01-16 19:26:03] heiglandreas@php.net

For easier check: https://3v4l.org/6Zjq5

------------------------------------------------------------------------
[2017-01-11 04:58:50] krakjoe@php.net

Derick, assigning to you: Can you take a quick look at this please ?

------------------------------------------------------------------------
[2017-01-04 11:46:00] cmb@php.net

This issue might be related to this years leap second.

------------------------------------------------------------------------
[2017-01-04 09:54:08] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=73858&edit=1


Thread (7 messages)

« previous php.bugs (#207255) next »