-
Notifications
You must be signed in to change notification settings - Fork 7.8k
DateTime object comparison after applying delta less than 1 second #8964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I reproduced this. From what I found, the problem seems to come from the change made in 091c092, exactly here in this file: Lines 3008 to 3012 in d86141a
Reverting the change gives the expected output. It seems that changing this initialisation to Line 3967 in d86141a
However, I'm not exactly sure that is the real fix. Is there any reason to initialize this especially with |
First, the actual output depends on the original microseconds; if these are greater than
The problem are negative ext/date/lib/tm2unixtime.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c
index 7740b25e97..80e72d3665 100644
--- a/ext/date/lib/tm2unixtime.c
+++ b/ext/date/lib/tm2unixtime.c
@@ -216,7 +216,11 @@ static void magic_date_calc(timelib_time *time)
void timelib_do_normalize(timelib_time* time)
{
+ timelib_sll old_s = time->s;
if (time->us != TIMELIB_UNSET) do_range_limit(0, 1000000, 1000000, &time->us, &time->s);
+ if (time->s != old_s) {
+ time->sse += time->s - old_s;
+ }
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i);
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h);
if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d); @derickr, can you please have a look? |
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 |
If negative values are not supported, these should be rejected, shouldn't they? |
Yes, they should, although I don't think it would still wholly solve the problem, as you could set |
<?php
$actual = date_create();
$expected = date_create();
$absDelta = abs(0.5);
$delta = new \DateInterval(sprintf('PT%dS', $absDelta));
$delta2 = (clone $delta);
$delta2->f = $absDelta - floor($absDelta);
$actualClone = (clone $actual)
->setTimezone(new DateTimeZone('UTC'));
$expectedLower = (clone $expected)
->setTimezone(new DateTimeZone('UTC'))
->sub($delta2);
$expectedUpper = (clone $expected)
->setTimezone(new DateTimeZone('UTC'))
->add($delta2);
var_dump($actualClone < $expectedLower, $actualClone > $expectedUpper); DateInterval::clone property f work. |
With HEAD of "master" I now sometimes get the expected result (twice |
You're going to have to be more precise than "sometimes", and with a simple test case. |
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 ( 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 |
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 :-) |
That's not correct. With the original test script (which uses the current time), I either get |
I've found another example of an issue with php8.1.0+ dates on StackOverflow. Minimal Example: https://3v4l.org/vmblR |
@alister That's not related - can you create a new issue? |
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). |
Description
The following code:
Started from php 8.1: https://3v4l.org/vvvWU
Code is reused from PHPUnit DateTimeComparator(SebastianBergmann\Comparator)
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.1
Operating System
No response
The text was updated successfully, but these errors were encountered: