Skip to content
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

\DateInterval 1.5s added to DateTimeInterface is rounded down since PHP 8.1.0 #9106

Closed
norberttech opened this issue Jul 22, 2022 · 3 comments

Comments

@norberttech
Copy link

Description

The following code:

<?php

$start = new \DateTimeImmutable("2020-01-01 00:00:00 UTC");

$oneAndHalfSec = new \DateInterval("PT1S");
$oneAndHalfSec->f = 0.5;

$t1 = $start->add($oneAndHalfSec);
$t2 = $t1->add($oneAndHalfSec);
$t3 = $t2->add($oneAndHalfSec);
$t4 = $t3->add($oneAndHalfSec);

var_dump($start->getTimestamp());
var_dump($t1->getTimestamp());
var_dump($t2->getTimestamp());
var_dump($t3->getTimestamp());
var_dump($t4->getTimestamp());

Resulted in this output in PHP 8.1.0 - 8.1.8:

int(1577836800)
int(1577836801)
int(1577836802)
int(1577836803)
int(1577836804)

But I expected this output instead, like in PHP 7.4.0 - 7.4.30, 8.0.1 - 8.0.21:

int(1577836800)
int(1577836801)
int(1577836803)
int(1577836804)
int(1577836806)

PHP Version

8.1.8

Operating System

No response

@cmb69
Copy link
Member

cmb69 commented Jul 23, 2022

Confirmed: https://3v4l.org/jV4V0. The issue is similar to #8964, but this time it is about timelib_add_wall() instead of timelib_sub_wall(). Particularly:

t->us += interval->us * bias;
if (bias == -1 && interval->us > 0) {
t->sse--;
}
timelib_do_normalize(t);

The addition in line 367 yields the correct result for the second addition (s=2, us=1000000), and the following timelib_do_normalize() correctly normalizes (s=3, us=0), but sse is not properly updated.

@derickr
Copy link
Member

derickr commented Jul 28, 2022

This is now fixed through #9176

@derickr derickr closed this as completed Jul 28, 2022
@norberttech
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants