Fix GH-10583: DateTime modify with tz pattern should not update linked timezone

This commit is contained in:
Derick Rethans 2023-03-23 11:46:31 +00:00
parent 8424b5caaa
commit cbac68df6b
3 changed files with 30 additions and 2 deletions

4
NEWS
View File

@ -16,6 +16,10 @@ PHP NEWS
. Fixed bug GH-10810 (Fix NUL byte terminating Exception::__toString()).
(ilutov)
- Date:
. Fixed bug GH-10583 (DateTime modify with tz pattern should not update
linked timezone). (Derick)
- FPM:
. Fixed bug GH-10611 (fpm_env_init_main leaks environ). (nielsdos)
. Destroy file_handle in fpm_main. (Jakub Zelenka, nielsdos)

View File

@ -2897,8 +2897,14 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
dateobj->time->us = tmp_time->us;
}
if (tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET) {
timelib_set_timezone_from_offset(dateobj->time, tmp_time->z);
/* Reset timezone to UTC if we detect a "@<ts>" modification */
if (
tmp_time->y == 1970 && tmp_time->m == 1 && tmp_time->d == 1 &&
tmp_time->h == 0 && tmp_time->i == 0 && tmp_time->s == 0 && tmp_time->us == 0 &&
tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET &&
tmp_time->z == 0 && tmp_time->dst == 0
) {
timelib_set_timezone_from_offset(dateobj->time, 0);
}
timelib_time_dtor(tmp_time);

View File

@ -0,0 +1,18 @@
--TEST--
Bug GH-10583 (DateTime modify with tz pattern should not update linked timezone)
--FILE--
<?php
$dt = new DateTime('2015-01-01 00:00:00+00:00');
var_dump($dt->format('c'));
var_dump($dt->modify('+1 s')->format('c'));
$dt = new DateTimeImmutable('2015-01-01 00:00:00+00:00');
var_dump($dt->format('c'));
var_dump($dt->modify('+1 s')->format('c'));
?>
--EXPECT--
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"