Skip to content

Commit 63aa5a4

Browse files
committed
Improve error message, and add additional test.
1 parent c85fcbc commit 63aa5a4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ext/date/php_date.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,12 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(const char *formal_tzname, const t
478478
static PHP_INI_MH(OnUpdate_date_timezone)
479479
{
480480
if (new_value && ZSTR_VAL(new_value) && !timelib_timezone_id_is_valid(ZSTR_VAL(new_value), DATE_TIMEZONEDB)) {
481-
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', using 'UTC' instead", ZSTR_VAL(new_value));
481+
php_error_docref(
482+
NULL, E_WARNING,
483+
"Invalid date.timezone value '%s', using '%s' instead",
484+
ZSTR_VAL(new_value),
485+
DATEG(default_timezone) ? DATEG(default_timezone) : "UTC"
486+
);
482487
return FAILURE;
483488
}
484489

@@ -493,7 +498,7 @@ static PHP_INI_MH(OnUpdate_date_timezone)
493498
/* {{{ Helper functions */
494499
static char* guess_timezone(const timelib_tzdb *tzdb)
495500
{
496-
/* Checking configure timezone */
501+
/* Checking whether timezone has been set with date_default_timezone_set() */
497502
if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) {
498503
return DATEG(timezone);
499504
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test invalid time zone and defaults
3+
--FILE--
4+
<?php
5+
echo ini_get("date.timezone"), "\n";
6+
7+
ini_set("date.timezone", "foo");
8+
echo ini_get("date.timezone"), "\n";
9+
10+
ini_set("date.timezone", "Europe/London");
11+
echo ini_get("date.timezone"), "\n";
12+
13+
ini_set("date.timezone", "Mars/Valles_Marineris");
14+
echo ini_get("date.timezone"), "\n";
15+
?>
16+
--EXPECTF--
17+
UTC
18+
19+
Warning: ini_set(): Invalid date.timezone value 'foo', using 'UTC' instead in %sini_set_incorrect-002.php on line %d
20+
UTC
21+
Europe/London
22+
23+
Warning: ini_set(): Invalid date.timezone value 'Mars/Valles_Marineris', using 'Europe/London' instead in %sini_set_incorrect-002.php on line %d
24+
Europe/London

0 commit comments

Comments
 (0)