Skip to content

Commit 438c798

Browse files
committed
Only warn when an incorrect timezone is set through 'date.timezone'
1 parent d5ff312 commit 438c798

9 files changed

+21
-19
lines changed

ext/date/php_date.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static PHP_INI_MH(OnUpdate_date_timezone);
9797

9898
/* {{{ INI Settings */
9999
PHP_INI_BEGIN()
100-
STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
100+
STD_PHP_INI_ENTRY("date.timezone", "UTC", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
101101
PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL)
102102
PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL)
103103
PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL)
@@ -497,21 +497,19 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(const char *formal_tzname, const t
497497
/* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
498498
static PHP_INI_MH(OnUpdate_date_timezone)
499499
{
500-
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
500+
DATEG(timezone_valid) = 0;
501+
502+
if (new_value && ZSTR_VAL(new_value) && !timelib_timezone_id_is_valid(ZSTR_VAL(new_value), DATE_TIMEZONEDB)) {
503+
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', using 'UTC' instead", ZSTR_VAL(new_value));
501504
return FAILURE;
502505
}
503506

504-
DATEG(timezone_valid) = 0;
505-
if (stage == PHP_INI_STAGE_RUNTIME) {
506-
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) {
507-
if (DATEG(default_timezone) && *DATEG(default_timezone)) {
508-
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s'", DATEG(default_timezone));
509-
}
510-
} else {
511-
DATEG(timezone_valid) = 1;
512-
}
507+
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
508+
return FAILURE;
513509
}
514510

511+
DATEG(timezone_valid) = 1;
512+
515513
return SUCCESS;
516514
}
517515
/* }}} */

ext/date/tests/bug73239.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ try {
1010
}
1111
?>
1212
--EXPECTF--
13-
Warning: ini_set(): Invalid date.timezone value 'dummy' in %sbug73239.php on line %d
14-
DateTime::__construct(): UTC was used as timezone, because the date.timezone value 'dummy' is invalid
13+
Warning: ini_set(): Invalid date.timezone value 'dummy', using 'UTC' instead in %sbug73239.php on line %d

ext/date/tests/date_default_timezone_get-1.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ date.timezone=
1313
echo date('e'), "\n";
1414
?>
1515
--EXPECT--
16+
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
1617
UTC
1718
UTC

ext/date/tests/date_default_timezone_get-2.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ date.timezone=
1212
echo date_default_timezone_get(), "\n";
1313
?>
1414
--EXPECT--
15+
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
1516
UTC

ext/date/tests/date_default_timezone_get-4.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ date.timezone=Incorrect/Zone
77
echo date_default_timezone_get(), "\n";
88
?>
99
--EXPECTF--
10-
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
10+
Warning: PHP Startup: Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %s on line %d
1111
UTC

ext/date/tests/date_default_timezone_set-1.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ date.timezone=
2121
echo date(DATE_ISO8601, $date3), "\n";
2222
echo date(DATE_ISO8601, $date4), "\n";
2323
?>
24-
--EXPECT--
24+
--EXPECTF--
25+
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in %s on line %d
2526
America/Indiana/Knox
2627
2005-01-12T03:00:00-0500
2728
2005-07-12T03:00:00-0500

ext/date/tests/ini_set_incorrect.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ini_set("date.timezone", "Incorrect/Zone");
77

88
?>
99
--EXPECTF--
10-
Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone' in %sini_set_incorrect.php on line %d
10+
Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %sini_set_incorrect.php on line %d

ext/intl/tests/dateformat_invalid_timezone.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ date.timezone=Mars/Utopia_Planitia
55
--SKIPIF--
66
<?php
77
extension_loaded('intl') || print 'skip';
8+
?>
89
--FILE--
910
<?php
1011

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

sapi/cli/tests/006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (PCRE_JIT_SUPPORT == false) {
1111
}
1212
?>
1313
--INI--
14-
date.timezone=
14+
date.timezone=UTC
1515
--FILE--
1616
<?php
1717

0 commit comments

Comments
 (0)