Only warn when an incorrect timezone is set through 'date.timezone'

This commit is contained in:
Derick Rethans 2022-05-27 13:47:52 +01:00
parent e0d21297fe
commit 6770158d47
9 changed files with 20 additions and 19 deletions

View file

@ -224,7 +224,7 @@ static PHP_INI_MH(OnUpdate_date_timezone);
/* {{{ INI Settings */ /* {{{ INI Settings */
PHP_INI_BEGIN() PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals) STD_PHP_INI_ENTRY("date.timezone", "UTC", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL) PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL) PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL) PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL)
@ -478,20 +478,18 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(const char *formal_tzname, const t
/* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */ /* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
static PHP_INI_MH(OnUpdate_date_timezone) static PHP_INI_MH(OnUpdate_date_timezone)
{ {
DATEG(timezone_valid) = 0;
if (new_value && ZSTR_VAL(new_value) && !timelib_timezone_id_is_valid(ZSTR_VAL(new_value), DATE_TIMEZONEDB)) {
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', using 'UTC' instead", ZSTR_VAL(new_value));
return FAILURE;
}
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) { if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
return FAILURE; return FAILURE;
} }
DATEG(timezone_valid) = 0;
if (stage == PHP_INI_STAGE_RUNTIME) {
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) {
if (DATEG(default_timezone) && *DATEG(default_timezone)) {
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s'", DATEG(default_timezone));
}
} else {
DATEG(timezone_valid) = 1; DATEG(timezone_valid) = 1;
}
}
return SUCCESS; return SUCCESS;
} }

View file

@ -10,5 +10,4 @@ try {
} }
?> ?>
--EXPECTF-- --EXPECTF--
Warning: ini_set(): Invalid date.timezone value 'dummy' in %sbug73239.php on line %d Warning: ini_set(): Invalid date.timezone value 'dummy', using 'UTC' instead in %sbug73239.php on line %d
DateTime::__construct(): UTC was used as timezone, because the date.timezone value 'dummy' is invalid

View file

@ -13,5 +13,6 @@ date.timezone=
echo date('e'), "\n"; echo date('e'), "\n";
?> ?>
--EXPECT-- --EXPECT--
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
UTC UTC
UTC UTC

View file

@ -12,4 +12,5 @@ date.timezone=
echo date_default_timezone_get(), "\n"; echo date_default_timezone_get(), "\n";
?> ?>
--EXPECT-- --EXPECT--
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
UTC UTC

View file

@ -7,5 +7,5 @@ date.timezone=Incorrect/Zone
echo date_default_timezone_get(), "\n"; echo date_default_timezone_get(), "\n";
?> ?>
--EXPECTF-- --EXPECTF--
Warning: date_default_timezone_get(): UTC was used as timezone, because the date.timezone value 'Incorrect/Zone' is invalid in %sdate_default_timezone_get-4.php on line %d Warning: PHP Startup: Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %s on line %d
UTC UTC

View file

@ -21,7 +21,8 @@ date.timezone=
echo date(DATE_ISO8601, $date3), "\n"; echo date(DATE_ISO8601, $date3), "\n";
echo date(DATE_ISO8601, $date4), "\n"; echo date(DATE_ISO8601, $date4), "\n";
?> ?>
--EXPECT-- --EXPECTF--
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in %s on line %d
America/Indiana/Knox America/Indiana/Knox
2005-01-12T03:00:00-0500 2005-01-12T03:00:00-0500
2005-07-12T03:00:00-0500 2005-07-12T03:00:00-0500

View file

@ -7,4 +7,4 @@ ini_set("date.timezone", "Incorrect/Zone");
?> ?>
--EXPECTF-- --EXPECTF--
Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone' in %sini_set_incorrect.php on line %d Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %sini_set_incorrect.php on line %d

View file

@ -14,5 +14,6 @@ try {
echo $e->getMessage(); echo $e->getMessage();
} }
?> ?>
--EXPECT-- --EXPECTF--
IntlDateFormatter::__construct(): UTC was used as timezone, because the date.timezone value 'Mars/Utopia_Planitia' is invalid Warning: PHP Startup: Invalid date.timezone value 'Mars/Utopia_Planitia', using 'UTC' instead in %s on line %d
Wat?

View file

@ -11,7 +11,7 @@ if (PCRE_JIT_SUPPORT == false) {
} }
?> ?>
--INI-- --INI--
date.timezone= date.timezone=UTC
--FILE-- --FILE--
<?php <?php