W3cubDocs

/Drupal 8

function drupal_get_user_timezone

drupal_get_user_timezone()

Returns the time zone of the current user.

File

core/includes/bootstrap.inc, line 514
Functions that need to be loaded on every Drupal request.

Code

function drupal_get_user_timezone() {
  $user = \Drupal::currentUser();
  $config = \Drupal::config('system.date');

  if ($user && $config->get('timezone.user.configurable') && $user->isAuthenticated() && $user->getTimezone()) {
    return $user->getTimezone();
  }
  else {
    // Ignore PHP strict notice if time zone has not yet been set in the php.ini
    // configuration.
    $config_data_default_timezone = $config->get('timezone.default');
    return !empty($config_data_default_timezone) ? $config_data_default_timezone : @date_default_timezone_get();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!bootstrap.inc/function/drupal_get_user_timezone/8.1.x