diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c6abcb27ef..98465ca462 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1138,6 +1138,40 @@ function phpbb_tz_select_compare($a, $b) } } +/** +* Return list of timezone identifiers +* We also add the selected timezone if we can create an object with it. +* DateTimeZone::listIdentifiers seems to not add all identifiers to the list, +* because some are only kept for backward compatible reasons. If the user has +* a deprecated value, we add it here, so it can still be kept. Once the user +* changed his value, there is no way back to deprecated values. +* +* @param string $selected_timezone Additional timezone that shall +* be added to the list of identiers +* @return array DateTimeZone::listIdentifiers and additional +* selected_timezone if it is a valid timezone. +*/ +function phpbb_get_timezone_identifiers($selected_timezone) +{ + $timezones = DateTimeZone::listIdentifiers(); + + if (!in_array($selected_timezone, $timezones)) + { + try + { + // Add valid timezones that are currently selected but not returned + // by DateTimeZone::listIdentifiers + $validate_timezone = new DateTimeZone($selected_timezone); + $timezones[] = $selected_timezone; + } + catch (Exception $e) + { + } + } + + return $timezones; +} + /** * Pick a timezone * @@ -1171,9 +1205,9 @@ function phpbb_timezone_select($default = '', $truncate = false) $default_offset = ''; if (!isset($timezones)) { - $unsorted_timezones = DateTimeZone::listIdentifiers(); - $timezones = array(); + $unsorted_timezones = phpbb_get_timezone_identifiers($default); + $timezones = array(); foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); @@ -1207,7 +1241,7 @@ function phpbb_timezone_select($default = '', $truncate = false) $opt_group = $timezone['offest']; $selected = ($default_offset == $timezone['offest']) ? ' selected="selected"' : ''; - $tz_dates .= ''; + $tz_dates .= ''; } if (isset($user->lang['timezones'][$timezone['tz']])) @@ -1229,7 +1263,7 @@ function phpbb_timezone_select($default = '', $truncate = false) } $selected = ($timezone['tz'] === $default) ? ' selected="selected"' : ''; - $tz_select .= ''; + $tz_select .= ''; } $tz_select .= ''; diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9bc72cbaa6..6e658b4ef4 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1420,7 +1420,7 @@ function validate_language_iso_name($lang_iso) */ function phpbb_validate_timezone($timezone) { - return (in_array($timezone, DateTimeZone::listIdentifiers())) ? false : 'TIMEZONE_INVALID'; + return (in_array($timezone, phpbb_get_timezone_identifiers($timezone))) ? false : 'TIMEZONE_INVALID'; } /**