function TimeZoneResolver::getTimeZone

Same name in other branches
  1. 9 core/modules/system/src/TimeZoneResolver.php \Drupal\system\TimeZoneResolver::getTimeZone()
  2. 8.9.x core/modules/system/src/TimeZoneResolver.php \Drupal\system\TimeZoneResolver::getTimeZone()
  3. 10 core/modules/system/src/TimeZoneResolver.php \Drupal\system\TimeZoneResolver::getTimeZone()

Gets the time zone based on site and user configuration.

Return value

string|null The time zone, or NULL if nothing is set.

1 call to TimeZoneResolver::getTimeZone()
TimeZoneResolver::setDefaultTimeZone in core/modules/system/src/TimeZoneResolver.php
Sets the default time zone.

File

core/modules/system/src/TimeZoneResolver.php, line 89

Class

TimeZoneResolver
Event handler that resolves time zone based on site and user configuration.

Namespace

Drupal\system

Code

protected function getTimeZone() {
    $config = $this->configFactory
        ->get('system.date');
    if ($config->get('timezone.user.configurable') && $this->currentUser
        ->isAuthenticated() && $this->currentUser
        ->getTimezone()) {
        return $this->currentUser
            ->getTimeZone();
    }
    elseif ($default_timezone = $config->get('timezone.default')) {
        return $default_timezone;
    }
    return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.