xref: /PHP-8.1/ext/date/tests/bug-gh8964-002.phpt (revision 7831a1ca)
1--TEST--
2Test for bug GH-8964: DateTime object comparison after applying delta less than 1 second
3--INI--
4date.timezone=UTC
5--FILE--
6<?php
7for ($seconds = 0; $seconds < 3; $seconds++)
8{
9	$actual   = new DateTimeImmutable("2022-07-21 15:00:10");
10	$delta    = new \DateInterval(sprintf('PT%dS', $seconds));
11	$delta->f = -0.9;
12
13	$expectedLower = $actual->sub($delta);
14	$expectedUpper = $actual->add($delta);
15
16	echo $expectedLower->format( 'H:i:s.u U' ), "\n";
17	echo $actual       ->format( 'H:i:s.u U' ), "\n";
18	echo $expectedUpper->format( 'H:i:s.u U' ), "\n";
19
20	var_dump($actual < $expectedLower, $actual > $expectedUpper);
21}
22?>
23--EXPECTF--
2415:00:10.900000 1658415610
2515:00:10.000000 1658415610
2615:00:09.100000 1658415609
27bool(true)
28bool(true)
2915:00:09.900000 1658415609
3015:00:10.000000 1658415610
3115:00:10.100000 1658415610
32bool(false)
33bool(false)
3415:00:08.900000 1658415608
3515:00:10.000000 1658415610
3615:00:11.100000 1658415611
37bool(false)
38bool(false)
39