Skip to content

Commit 50ca489

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents d9e8941 + 94d6bcb commit 50ca489

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

ext/date/php_date.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -3132,8 +3132,14 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
31323132
dateobj->time->us = tmp_time->us;
31333133
}
31343134

3135-
if (tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET) {
3136-
timelib_set_timezone_from_offset(dateobj->time, tmp_time->z);
3135+
/* Reset timezone to UTC if we detect a "@<ts>" modification */
3136+
if (
3137+
tmp_time->y == 1970 && tmp_time->m == 1 && tmp_time->d == 1 &&
3138+
tmp_time->h == 0 && tmp_time->i == 0 && tmp_time->s == 0 && tmp_time->us == 0 &&
3139+
tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET &&
3140+
tmp_time->z == 0 && tmp_time->dst == 0
3141+
) {
3142+
timelib_set_timezone_from_offset(dateobj->time, 0);
31373143
}
31383144

31393145
timelib_time_dtor(tmp_time);

ext/date/tests/gh10583.phpt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug GH-10583 (DateTime modify with tz pattern should not update linked timezone)
3+
--FILE--
4+
<?php
5+
6+
$dt = new DateTime('2015-01-01 00:00:00+00:00');
7+
var_dump($dt->format('c'));
8+
var_dump($dt->modify('+1 s')->format('c'));
9+
10+
$dt = new DateTimeImmutable('2015-01-01 00:00:00+00:00');
11+
var_dump($dt->format('c'));
12+
var_dump($dt->modify('+1 s')->format('c'));
13+
?>
14+
--EXPECT--
15+
string(25) "2015-01-01T00:00:00+00:00"
16+
string(25) "2015-01-01T00:00:00+00:00"
17+
string(25) "2015-01-01T00:00:00+00:00"
18+
string(25) "2015-01-01T00:00:00+00:00"

0 commit comments

Comments
 (0)