Bug #78673 [Ver->Csd]: Wrong results for DateTime->modify() with milliseconds

From: Date: Tue, 15 Oct 2019 19:31:25 +0000
Subject: Bug #78673 [Ver->Csd]: Wrong results for DateTime->modify() with milliseconds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223213@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
 Updated by:         derick@php.net
 Reported by:        dse at newpharma dot ro
 Summary:            Wrong results for DateTime->modify() with
                     milliseconds
-Status:             Verified
+Status:             Closed
 Type:               Bug
 Package:            Date/time related
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

This has been fixed in timelib now, which will soon make it into PHP too.


Previous Comments:
------------------------------------------------------------------------
[2019-10-15 10:44:34] derick@php.net

The code definitely normalizes the fractions:

void timelib_do_normalize(timelib_time* time)
{
    if (time->us != TIMELIB_UNSET) do_range_limit_fraction(&time->us, &time->s);

So I'm going to have to see why this doesn't work.

------------------------------------------------------------------------
[2019-10-15 09:13:28] dse at newpharma dot ro

Just want to add that same issue also happens with microseconds:
https://3v4l.org/Usapt

------------------------------------------------------------------------
[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


Thread (6 messages)

« previous php.bugs (#223213) next »