You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateTime object comparison after applying delta less than 1 second #8964
However, I'm not exactly sure that is the real fix. Is there any reason to initialize this especially with PHP_DATE_WALL value, when creating a DateInterval?
First, the actual output depends on the original microseconds; if these are greater than 500000, we get the reported result. Otherwise we get
bool(false)
bool(true)
The problem are negative us in timelib_sub_wall() and timelib_add_wall(). While timelib_do_normalize() normalizes the us and adjusts s accordingly, the sse are not updated. Quick and dirty patch:
Yes, they should, although I don't think it would still wholly solve the problem, as you could set ->f larger than 1, and the sse would still not have been updated...
See, for instance, https://3v4l.org/9FElH. I get the same result as they report for 8.1 locally with current "master". While the results of adding/subtracting the interval look correct, the comparison result ($actualClose > $expectedUpper) does not.
Simplified example: https://3v4l.org/Kott5. The results prior to 8.1.0 look correct to me; apparently latest timelib (still) does not adjust the sse in this case.
With HEAD of "master" I now sometimes get the expected result (twice false), but sometimes still the erroneous true,false or false,true.
That's not correct. With the original test script (which uses the current time), I either get false,false, or false,true, so the subtraction issue is fixed. It is indeed only about timelib_add_wall().
I've found another example of an issue with php8.1.0+ dates on StackOverflow.
Minimal Example: https://3v4l.org/vmblR
Here there is one date with a default TZ set from date_default_timezone_set('Europe/Helsinki');, and another with an internal TZ of +300 (originally from (new DateTime('2022-05-24 17:35:00'))->format('r'))
I"m going to close this, as this is now fixed for timelib_sub_wall, with #9106 covering the timelib_add_wall issue (for which a patch is on the way too).
Activity
[-]DateTime object comparison [/-][+]DateTime object comparison after applying delta less than 1 second[/+]alexandre-daubois commentedon Jul 10, 2022
I reproduced this. From what I found, the problem seems to come from the change made in 091c092, exactly here in this file:
php-src/ext/date/php_date.c
Lines 3008 to 3012 in d86141a
Reverting the change gives the expected output. It seems that changing this initialisation to
PHP_DATE_CIVILalso does the trick:php-src/ext/date/php_date.c
Line 3967 in d86141a
However, I'm not exactly sure that is the real fix. Is there any reason to initialize this especially with
PHP_DATE_WALLvalue, when creating aDateInterval?cmb69 commentedon Jul 11, 2022
First, the actual output depends on the original microseconds; if these are greater than
500000, we get the reported result. Otherwise we getThe problem are negative
usintimelib_sub_wall()andtimelib_add_wall(). Whiletimelib_do_normalize()normalizes theusand adjustssaccordingly, thesseare not updated. Quick and dirty patch:@derickr, can you please have a look?
derickr commentedon Jul 15, 2022
This looks fixed in 8.1.7 already? See https://3v4l.org/vkpcb
Although the real problem here is you writing negative values to the
->fproperty.cmb69 commentedon Jul 15, 2022
If negative values are not supported, these should be rejected, shouldn't they?
derickr commentedon Jul 15, 2022
Yes, they should, although I don't think it would still wholly solve the problem, as you could set
->flarger than1, and the sse would still not have been updated...Add test case for phpGH-8964
hormus commentedon Jul 22, 2022
DateInterval::clone property f work.
cmb69 commentedon Jul 23, 2022
With HEAD of "master" I now sometimes get the expected result (twice
false), but sometimes still the erroneoustrue,falseorfalse,true.derickr commentedon Jul 24, 2022
You're going to have to be more precise than "sometimes", and with a simple test case.
cmb69 commentedon Jul 24, 2022
See, for instance, https://3v4l.org/9FElH. I get the same result as they report for 8.1 locally with current "master". While the results of adding/subtracting the interval look correct, the comparison result (
$actualClose > $expectedUpper) does not.Simplified example: https://3v4l.org/Kott5. The results prior to 8.1.0 look correct to me; apparently latest timelib (still) does not adjust the
ssein this case.derickr commentedon Jul 24, 2022
OK, my changes only affected timelib_sub_wall, and i couldn't see anything wrong with add_wall when I tested. I'll have another look. Sigh :-)
cmb69 commentedon Jul 24, 2022
That's not correct. With the original test script (which uses the current time), I either get
false,false, orfalse,true, so the subtraction issue is fixed. It is indeed only abouttimelib_add_wall().alister commentedon Jul 27, 2022
I've found another example of an issue with php8.1.0+ dates on StackOverflow.
Minimal Example: https://3v4l.org/vmblR
Here there is one date with a default TZ set from
date_default_timezone_set('Europe/Helsinki');, and another with an internal TZ of +300 (originally from(new DateTime('2022-05-24 17:35:00'))->format('r'))derickr commentedon Jul 28, 2022
@alister That's not related - can you create a new issue?
derickr commentedon Jul 28, 2022
I"m going to close this, as this is now fixed for timelib_sub_wall, with #9106 covering the timelib_add_wall issue (for which a patch is on the way too).