Improve error message, and add additional test.

This commit is contained in:
Derick Rethans 2022-05-30 19:08:52 +01:00
parent c85fcbc218
commit 63aa5a4b5d
2 changed files with 31 additions and 2 deletions

View File

@ -478,7 +478,12 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(const char *formal_tzname, const t
static PHP_INI_MH(OnUpdate_date_timezone)
{
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));
php_error_docref(
NULL, E_WARNING,
"Invalid date.timezone value '%s', using '%s' instead",
ZSTR_VAL(new_value),
DATEG(default_timezone) ? DATEG(default_timezone) : "UTC"
);
return FAILURE;
}
@ -493,7 +498,7 @@ static PHP_INI_MH(OnUpdate_date_timezone)
/* {{{ Helper functions */
static char* guess_timezone(const timelib_tzdb *tzdb)
{
/* Checking configure timezone */
/* Checking whether timezone has been set with date_default_timezone_set() */
if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) {
return DATEG(timezone);
}

View File

@ -0,0 +1,24 @@
--TEST--
Test invalid time zone and defaults
--FILE--
<?php
echo ini_get("date.timezone"), "\n";
ini_set("date.timezone", "foo");
echo ini_get("date.timezone"), "\n";
ini_set("date.timezone", "Europe/London");
echo ini_get("date.timezone"), "\n";
ini_set("date.timezone", "Mars/Valles_Marineris");
echo ini_get("date.timezone"), "\n";
?>
--EXPECTF--
UTC
Warning: ini_set(): Invalid date.timezone value 'foo', using 'UTC' instead in %sini_set_incorrect-002.php on line %d
UTC
Europe/London
Warning: ini_set(): Invalid date.timezone value 'Mars/Valles_Marineris', using 'Europe/London' instead in %sini_set_incorrect-002.php on line %d
Europe/London