1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

Add test case for GH-8964

This commit is contained in:
Derick Rethans
2022-07-22 11:30:00 +01:00
parent 0d3061d225
commit 7831a1cae6
3 changed files with 65 additions and 0 deletions

2
NEWS
View File

@@ -8,6 +8,8 @@ PHP NEWS
- Date:
. Fixed bug GH-8730 (DateTime::diff miscalculation is same time zone of
different type). (Derick)
. Fixed bug GH-8964 (DateTime object comparison after applying delta less
than 1 second). (Derick)
. Fixed bug #81263 (Wrong result from DateTimeImmutable::diff). (Derick)
- DBA:

View File

@@ -0,0 +1,25 @@
--TEST--
Test for bug GH-8964: DateTime object comparison after applying delta less than 1 second
--INI--
date.timezone=UTC
--FILE--
<?php
$actual = new DateTimeImmutable("2022-07-21 15:00:10");
$delta = new \DateInterval(sprintf('PT%dS', 0));
$delta->f = 0.9;
$expectedLower = $actual->sub($delta);
$expectedUpper = $actual->add($delta);
echo $expectedLower->format( 'H:i:s.u U' ), "\n";
echo $actual ->format( 'H:i:s.u U' ), "\n";
echo $expectedUpper->format( 'H:i:s.u U' ), "\n";
var_dump($actual < $expectedLower, $actual > $expectedUpper);
?>
--EXPECTF--
15:00:09.100000 1658415609
15:00:10.000000 1658415610
15:00:10.900000 1658415610
bool(false)
bool(false)

View File

@@ -0,0 +1,38 @@
--TEST--
Test for bug GH-8964: DateTime object comparison after applying delta less than 1 second
--INI--
date.timezone=UTC
--FILE--
<?php
for ($seconds = 0; $seconds < 3; $seconds++)
{
$actual = new DateTimeImmutable("2022-07-21 15:00:10");
$delta = new \DateInterval(sprintf('PT%dS', $seconds));
$delta->f = -0.9;
$expectedLower = $actual->sub($delta);
$expectedUpper = $actual->add($delta);
echo $expectedLower->format( 'H:i:s.u U' ), "\n";
echo $actual ->format( 'H:i:s.u U' ), "\n";
echo $expectedUpper->format( 'H:i:s.u U' ), "\n";
var_dump($actual < $expectedLower, $actual > $expectedUpper);
}
?>
--EXPECTF--
15:00:10.900000 1658415610
15:00:10.000000 1658415610
15:00:09.100000 1658415609
bool(true)
bool(true)
15:00:09.900000 1658415609
15:00:10.000000 1658415610
15:00:10.100000 1658415610
bool(false)
bool(false)
15:00:08.900000 1658415608
15:00:10.000000 1658415610
15:00:11.100000 1658415611
bool(false)
bool(false)