Skip to content

Commit 7e22419

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 54f92fc + 50ca489 commit 7e22419

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
@@ -3162,8 +3162,14 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{
31623162
dateobj->time->us = tmp_time->us;
31633163
}
31643164

3165-
if (tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET) {
3166-
timelib_set_timezone_from_offset(dateobj->time, tmp_time->z);
3165+
/* Reset timezone to UTC if we detect a "@<ts>" modification */
3166+
if (
3167+
tmp_time->y == 1970 && tmp_time->m == 1 && tmp_time->d == 1 &&
3168+
tmp_time->h == 0 && tmp_time->i == 0 && tmp_time->s == 0 && tmp_time->us == 0 &&
3169+
tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET &&
3170+
tmp_time->z == 0 && tmp_time->dst == 0
3171+
) {
3172+
timelib_set_timezone_from_offset(dateobj->time, 0);
31673173
}
31683174

31693175
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)