DateTime object comparison after applying delta less than 1 second #8964
Closed
Description
Description
The following code:
Started from php 8.1: https://3v4l.org/vvvWU
Code is reused from PHPUnit DateTimeComparator(SebastianBergmann\Comparator)
<?php
$actual = date_create();
$expected = date_create();
$absDelta = abs(0.5);
$delta = new \DateInterval(sprintf('PT%dS', $absDelta));
$delta->f = $absDelta - floor($absDelta);
$actualClone = (clone $actual)
->setTimezone(new DateTimeZone('UTC'));
$expectedLower = (clone $expected)
->setTimezone(new DateTimeZone('UTC'))
->sub($delta);
$expectedUpper = (clone $expected)
->setTimezone(new DateTimeZone('UTC'))
->add($delta);
var_dump($actualClone < $expectedLower, $actualClone > $expectedUpper);
Resulted in this output:
bool(true)
bool(false)
But I expected this output instead:
bool(false)
bool(false)
PHP Version
PHP 8.1
Operating System
No response