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:
2
NEWS
2
NEWS
@@ -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:
|
||||
|
||||
25
ext/date/tests/bug-gh8964-001.phpt
Normal file
25
ext/date/tests/bug-gh8964-001.phpt
Normal 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)
|
||||
38
ext/date/tests/bug-gh8964-002.phpt
Normal file
38
ext/date/tests/bug-gh8964-002.phpt
Normal 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)
|
||||
Reference in New Issue
Block a user