Bug #78673 [Com]: Wrong results for DateTime->modify() with milliseconds
| From: | dse at newpharma dot ro | Date: | Tue, 15 Oct 2019 09:13:28 +0000 |
| Subject: | Bug #78673 [Com]: Wrong results for DateTime->modify() with milliseconds | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223208@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78673&edit=1
ID: 78673
Comment by: dse at newpharma dot ro
Reported by: dse at newpharma dot ro
Summary: Wrong results for DateTime->modify() with
milliseconds
Status: Verified
Type: Bug
Package: Date/time related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Just want to add that same issue also happens with microseconds:
https://3v4l.org/Usapt
Previous Comments:
------------------------------------------------------------------------
[2019-10-14 14:45:27] cmb@php.net
See also <https://3v4l.org/FVLs5>.
Looks like the result is not normalized.
------------------------------------------------------------------------
[2019-10-14 13:55:30] dse at newpharma dot ro
Description:
------------
Adding or subtracting milliseconds from a DateTime object does not give the correct result.
Test script:
---------------
<?php
$millisInThePast = 50000;
$currentDate = new DateTime("2019-10-14T15:08:23.123+02:00");
echo 'Current: ' . $currentDate->format(DATE_RFC3339_EXTENDED) . "\n";
echo 'Past: ' . $currentDate->modify("-{$millisInThePast}
msec")->format(DATE_RFC3339_EXTENDED);
Expected result:
----------------
Current: 2019-10-14T15:08:23.123+02:00
Past: 2019-10-14T15:07:33.123+02:00
Actual result:
--------------
Current: 2019-10-14T15:08:23.123+02:00
Past: 2019-10-14T15:08:21.-47877+02:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78673&edit=1