1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 11:13:36 +02:00

Merge remote-tracking branch 'derickr/timelib-2021-15-sync' into PHP-8.1

This commit is contained in:
Derick Rethans
2022-07-22 13:07:28 +01:00
5 changed files with 83 additions and 9 deletions
+2
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:
+15 -6
View File
@@ -405,12 +405,21 @@ timelib_time *timelib_sub_wall(timelib_time *old_time, timelib_rel_time *interva
timelib_update_ts(t, NULL);
}
do_range_limit(0, 1000000, 1000000, &interval->us, &interval->s);
t->sse -= bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
timelib_update_from_sse(t);
t->us -= interval->us * bias;
if (bias == -1 && interval->us > 0) {
t->sse++;
if (interval->us == 0) {
t->sse -= bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
timelib_update_from_sse(t);
} else {
timelib_rel_time *temp_interval = timelib_rel_time_clone(interval);
do_range_limit(0, 1000000, 1000000, &temp_interval->us, &temp_interval->s);
t->sse -= bias * timelib_hms_to_seconds(temp_interval->h, temp_interval->i, temp_interval->s);
timelib_update_from_sse(t);
t->us -= temp_interval->us * bias;
timelib_do_normalize(t);
timelib_update_ts(t, NULL);
timelib_rel_time_dtor(temp_interval);
}
timelib_do_normalize(t);
}
+3 -3
View File
@@ -30,9 +30,9 @@
# include "timelib_config.h"
#endif
#define TIMELIB_VERSION 202114
#define TIMELIB_EXTENDED_VERSION 20211401
#define TIMELIB_ASCII_VERSION "2021.14"
#define TIMELIB_VERSION 202115
#define TIMELIB_EXTENDED_VERSION 20211501
#define TIMELIB_ASCII_VERSION "2021.15"
#include <stdlib.h>
#include <stdbool.h>
+25
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)
+38
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)