Bug #73858 [NEW]: diff() of two relative/described DateTimes is wrong
| From: | nd at pcmltd dot eu | Date: | Wed, 04 Jan 2017 09:54:12 +0000 |
| Subject: | Bug #73858 [NEW]: diff() of two relative/described DateTimes is wrong | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-206293@lists.php.net to get a copy of this message | ||
From: nd at pcmltd dot eu
Operating system: Ubuntu 16.04.1 LTS
PHP version: 7.0.14
Package: Date/time related
Bug Type: Bug
Bug description:diff() of two relative/described DateTimes is wrong
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 bug report at https://bugs.php.net/bug.php?id=73858&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73858&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73858&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73858&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73858&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73858&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73858&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73858&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73858&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73858&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73858&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73858&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73858&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73858&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73858&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73858&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73858&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73858&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73858&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73858&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73858&r=mysqlcfg