Skip to content

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

Closed

Description

@norberttech

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

Activity

  1. cmb69 commented on Jul 23, 2022

    @cmb69
    Member

    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.

  2. derickr commented on Jul 28, 2022

    @derickr
    Member

    This is now fixed through #9176

  3. norberttech commented on Jul 28, 2022

    @norberttech
    Author

    Thanks!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions