Skip to content

Commit 7831a1c

Browse files
committed
Add test case for GH-8964
1 parent 0d3061d commit 7831a1c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
- Date:
99
. Fixed bug GH-8730 (DateTime::diff miscalculation is same time zone of
1010
different type). (Derick)
11+
. Fixed bug GH-8964 (DateTime object comparison after applying delta less
12+
than 1 second). (Derick)
1113
. Fixed bug #81263 (Wrong result from DateTimeImmutable::diff). (Derick)
1214

1315
- DBA:

ext/date/tests/bug-gh8964-001.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test for bug GH-8964: DateTime object comparison after applying delta less than 1 second
3+
--INI--
4+
date.timezone=UTC
5+
--FILE--
6+
<?php
7+
$actual = new DateTimeImmutable("2022-07-21 15:00:10");
8+
$delta = new \DateInterval(sprintf('PT%dS', 0));
9+
$delta->f = 0.9;
10+
11+
$expectedLower = $actual->sub($delta);
12+
$expectedUpper = $actual->add($delta);
13+
14+
echo $expectedLower->format( 'H:i:s.u U' ), "\n";
15+
echo $actual ->format( 'H:i:s.u U' ), "\n";
16+
echo $expectedUpper->format( 'H:i:s.u U' ), "\n";
17+
18+
var_dump($actual < $expectedLower, $actual > $expectedUpper);
19+
?>
20+
--EXPECTF--
21+
15:00:09.100000 1658415609
22+
15:00:10.000000 1658415610
23+
15:00:10.900000 1658415610
24+
bool(false)
25+
bool(false)

ext/date/tests/bug-gh8964-002.phpt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Test for bug GH-8964: DateTime object comparison after applying delta less than 1 second
3+
--INI--
4+
date.timezone=UTC
5+
--FILE--
6+
<?php
7+
for ($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--
24+
15:00:10.900000 1658415610
25+
15:00:10.000000 1658415610
26+
15:00:09.100000 1658415609
27+
bool(true)
28+
bool(true)
29+
15:00:09.900000 1658415609
30+
15:00:10.000000 1658415610
31+
15:00:10.100000 1658415610
32+
bool(false)
33+
bool(false)
34+
15:00:08.900000 1658415608
35+
15:00:10.000000 1658415610
36+
15:00:11.100000 1658415611
37+
bool(false)
38+
bool(false)

0 commit comments

Comments
 (0)