diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index c3069ebd5..29c91f5d9 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -478,27 +478,31 @@ abstract class ApplicationBootstrap } /** - * Setup default timezone + * Detect the timezone * - * @return self - * @throws ConfigurationError if the timezone in config.ini isn't valid + * @return null|string */ - protected function setupTimezone() + protected function detectTimezone() { - $detect = new TimezoneDetect(); + return null; + } - if ($detect->success()) { - $default = $detect->getTimezoneName(); - } else { - $default = @date_default_timezone_get(); + /** + * Set up the timezone + * + * @return $this + */ + protected final function setupTimezone() + { + $timezone = $this->detectTimeZone(); + if ($timezone === null || @date_default_timezone_set($timezone) === false) { + $timezone = @date_default_timezone_get(); + if ($timezone === false) { + $timezone = 'UTC'; + date_default_timezone_set($timezone); + } } - - if (! $default) { - $default = 'UTC'; - } - $timeZoneString = $this->config->fromSection('global', 'timezone', $default); - date_default_timezone_set($timeZoneString); - DateTimeFactory::setConfig(array('timezone' => $timeZoneString)); + DateTimeFactory::setConfig(array('timezone' => $timezone)); return $this; } diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 67bcdb4aa..3f08d0b64 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -291,31 +291,19 @@ class Web extends ApplicationBootstrap } /** - * Setup user timezone if set and valid, otherwise global default timezone - * - * @return self - * @see ApplicationBootstrap::setupTimezone + * (non-PHPDoc) + * @see ApplicationBootstrap::detectTimezone() For the method documentation. */ - protected function setupTimezone() + protected function detectTimezone() { $auth = Manager::getInstance(); - - if ($auth->isAuthenticated() && - ($timezone = $auth->getUser()->getPreferences()->getValue('icingaweb', 'timezone')) !== null + if (! $auth->isAuthenticated() + || ($timezone = $auth->getUser()->getPreferences()->getValue('icingaweb', 'timezone')) === null ) { - $userTimezone = $timezone; - } else { - $userTimezone = null; + $detect = new TimezoneDetect(); + $timezone = $detect->getTimezoneName(); } - - try { - DateTimeFactory::setConfig(array('timezone' => $userTimezone)); - date_default_timezone_set($userTimezone); - } catch (ConfigurationError $e) { - return parent::setupTimezone(); - } - - return $this; + return $timezone; } /**