Skip to content

Commit 6b212b6

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents bfa56cf + b73e1db commit 6b212b6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

ext/date/php_date.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,6 +3052,10 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
30523052
dateobj->time->us = tmp_time->us;
30533053
}
30543054

3055+
if (tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET) {
3056+
timelib_set_timezone_from_offset(dateobj->time, tmp_time->z);
3057+
}
3058+
30553059
timelib_time_dtor(tmp_time);
30563060

30573061
timelib_update_ts(dateobj->time, NULL);

ext/date/tests/gh9891.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug GH-9891 (DateTime modify with unixtimestamp (@) must work like setTimestamp)
3+
--FILE--
4+
<?php
5+
$m = new DateTime('2022-12-20 14:30:25', new DateTimeZone('Europe/Paris'));
6+
$m->modify('@1234567890');
7+
var_dump($m->getTimeStamp());
8+
9+
echo "=======\n";
10+
11+
$a = new DateTime('2022-11-01 13:30:00', new DateTimezone('America/Lima'));
12+
$b = clone $a;
13+
echo '$a: ', $a->format(DateTime::ATOM), "\n";
14+
echo '$b: ', $b->format(DateTime::ATOM), "\n";
15+
echo '$a: @', $a->getTimestamp(), "\n";
16+
echo '$b: setTimestamp(', $b->getTimestamp(), ")\n";
17+
$a->modify('@' . $a->getTimestamp());
18+
$b->setTimestamp($b->getTimestamp());
19+
echo '$a: ', $a->format(DateTime::ATOM), "\n";
20+
echo '$b: ', $b->format(DateTime::ATOM), "\n";
21+
?>
22+
--EXPECT--
23+
int(1234567890)
24+
=======
25+
$a: 2022-11-01T13:30:00-05:00
26+
$b: 2022-11-01T13:30:00-05:00
27+
$a: @1667327400
28+
$b: setTimestamp(1667327400)
29+
$a: 2022-11-01T18:30:00+00:00
30+
$b: 2022-11-01T13:30:00-05:00

0 commit comments

Comments
 (0)