Skip to content

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

Closed
@norberttech

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions