Bug #81106 [Com]: Regression in 8.1: add() now truncate ->f
| From: | patrickallaert@php.net | Date: | Wed, 09 Jun 2021 18:32:16 +0000 |
| Subject: | Bug #81106 [Com]: Regression in 8.1: add() now truncate ->f | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234318@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81106&edit=1
ID: 81106
Comment by: patrickallaert@php.net
Reported by: kylekatarnls at gmail dot com
Summary: Regression in 8.1: add() now truncate ->f
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Ubuntu
PHP Version: master-Git-2021-06-04 (Git)
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Introduced in https://github.com/php/php-src/commit/091c0920b9db057a54dc43ece6e864bce6818d5e
Previous Comments:
------------------------------------------------------------------------
[2021-06-04 19:08:12] kylekatarnls at gmail dot com
Me again, it's going very unexpected when using negative number:
->f = -1.234
=> Add 0.766 seconds
------------------------------------------------------------------------
[2021-06-04 18:22:12] kylekatarnls at gmail dot com
For the record, it's not consistent with what happen with ->s = 78 which properly add 78
seconds in both PHP 8.0 and 8.1
------------------------------------------------------------------------
[2021-06-04 17:41:46] kylekatarnls at gmail dot com
Description:
------------
An interval with ->f = 1.234 was previously understood as 1.234 second when using in
DateTime::add() which sounds pretty consistent.
Now it's understood as 0.234 which feels pretty unsafe. Moreover, if we dump the interval, we
see ->f value is still 1.234.
If ->f can now longer be >= 1, it would rather need to throw an exception rather than
accepting it and be interpreted differently regarding where it's used.
Test script:
---------------
$dateInterval = new DateInterval('PT0S');
$dateInterval->f = 1.234;
echo (new DateTimeImmutable('2000-01-01
00:00:00'))->add($dateInterval)->format('Y-m-d H:i:s.u');
Expected result:
----------------
2000-01-01 00:00:01.234000
(What we got for PHP <= 8.0)
Actual result:
--------------
2000-01-01 00:00:00.234000
(What we get now with master branch)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81106&edit=1