Skip to content

Commit cbac68d

Browse files
committed
Fix GH-10583: DateTime modify with tz pattern should not update linked timezone
1 parent 8424b5c commit cbac68d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug GH-10810 (Fix NUL byte terminating Exception::__toString()).
1717
(ilutov)
1818

19+
- Date:
20+
. Fixed bug GH-10583 (DateTime modify with tz pattern should not update
21+
linked timezone). (Derick)
22+
1923
- FPM:
2024
. Fixed bug GH-10611 (fpm_env_init_main leaks environ). (nielsdos)
2125
. Destroy file_handle in fpm_main. (Jakub Zelenka, nielsdos)

ext/date/php_date.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -2897,8 +2897,14 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
28972897
dateobj->time->us = tmp_time->us;
28982898
}
28992899

2900-
if (tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET) {
2901-
timelib_set_timezone_from_offset(dateobj->time, tmp_time->z);
2900+
/* Reset timezone to UTC if we detect a "@<ts>" modification */
2901+
if (
2902+
tmp_time->y == 1970 && tmp_time->m == 1 && tmp_time->d == 1 &&
2903+
tmp_time->h == 0 && tmp_time->i == 0 && tmp_time->s == 0 && tmp_time->us == 0 &&
2904+
tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET &&
2905+
tmp_time->z == 0 && tmp_time->dst == 0
2906+
) {
2907+
timelib_set_timezone_from_offset(dateobj->time, 0);
29022908
}
29032909

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