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

From: Date: Tue, 15 Oct 2019 10:44:34 +0000
Subject: Bug #78673 [Ver]: Wrong results for DateTime->modify() with milliseconds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223209@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 Type: Bug Package: Date/time related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#223209) next »