Skip to content

Commit dd241c0

Browse files
committed
Merge remote-tracking branch 'derickr/timelib-sync-20220728' into PHP-8.1
2 parents 566f902 + a0c01f3 commit dd241c0

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
different type). (Derick)
1111
. Fixed bug GH-8964 (DateTime object comparison after applying delta less
1212
than 1 second). (Derick)
13+
. Fixed bug GH-9106: (DateInterval 1.5s added to DateTimeInterface is rounded
14+
down since PHP 8.1.0). (Derick)
1315
. Fixed bug #81263 (Wrong result from DateTimeImmutable::diff). (Derick)
1416

1517
- DBA:

ext/date/lib/interval.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,21 @@ timelib_time *timelib_add_wall(timelib_time *old_time, timelib_rel_time *interva
361361
timelib_update_ts(t, NULL);
362362
}
363363

364-
do_range_limit(0, 1000000, 1000000, &interval->us, &interval->s);
365-
t->sse += bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
366-
timelib_update_from_sse(t);
367-
t->us += interval->us * bias;
368-
if (bias == -1 && interval->us > 0) {
369-
t->sse--;
364+
if (interval->us == 0) {
365+
t->sse += bias * timelib_hms_to_seconds(interval->h, interval->i, interval->s);
366+
timelib_update_from_sse(t);
367+
} else {
368+
timelib_rel_time *temp_interval = timelib_rel_time_clone(interval);
369+
370+
do_range_limit(0, 1000000, 1000000, &temp_interval->us, &temp_interval->s);
371+
t->sse += bias * timelib_hms_to_seconds(temp_interval->h, temp_interval->i, temp_interval->s);
372+
timelib_update_from_sse(t);
373+
t->us += temp_interval->us * bias;
374+
375+
timelib_do_normalize(t);
376+
timelib_update_ts(t, NULL);
377+
378+
timelib_rel_time_dtor(temp_interval);
370379
}
371380
timelib_do_normalize(t);
372381
}

ext/date/lib/timelib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
# include "timelib_config.h"
3131
#endif
3232

33-
#define TIMELIB_VERSION 202115
34-
#define TIMELIB_EXTENDED_VERSION 20211501
35-
#define TIMELIB_ASCII_VERSION "2021.15"
33+
#define TIMELIB_VERSION 202116
34+
#define TIMELIB_EXTENDED_VERSION 20211601
35+
#define TIMELIB_ASCII_VERSION "2021.16"
3636

3737
#include <stdlib.h>
3838
#include <stdbool.h>

ext/date/tests/bug-gh9106.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Test for bug GH-9601: DateInterval 1.5s added to DateTimeInterface is rounded down since PHP 8.1.0
3+
--INI--
4+
date.timezone=UTC
5+
--FILE--
6+
<?php
7+
8+
$start = new \DateTimeImmutable("2020-01-01 00:00:00 UTC");
9+
10+
$oneAndHalfSec = new \DateInterval("PT1S");
11+
$oneAndHalfSec->f = 0.5;
12+
13+
$t1 = $start->add($oneAndHalfSec);
14+
$t2 = $t1->add($oneAndHalfSec);
15+
$t3 = $t2->add($oneAndHalfSec);
16+
$t4 = $t3->add($oneAndHalfSec);
17+
18+
var_dump($start->getTimestamp());
19+
var_dump($t1->getTimestamp());
20+
var_dump($t2->getTimestamp());
21+
var_dump($t3->getTimestamp());
22+
var_dump($t4->getTimestamp());
23+
?>
24+
--EXPECT--
25+
int(1577836800)
26+
int(1577836801)
27+
int(1577836803)
28+
int(1577836804)
29+
int(1577836806)

0 commit comments

Comments
 (0)