You are here

function views_get_timezone in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 includes/handlers.inc \views_get_timezone()
  2. 7.3 includes/handlers.inc \views_get_timezone()

Figure out what timezone we're in; needed for some date manipulations.

1 call to views_get_timezone()
views_date_sql_field in includes/handlers.inc
Helper function to create cross-database SQL dates.

File

includes/handlers.inc, line 835
handlers.inc Defines the various handler objects to help build and display views.

Code

function views_get_timezone() {
  global $user;
  if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
    $timezone = $user->timezone;
  }
  else {
    $timezone = variable_get('date_default_timezone', 0);
  }

  // set up the database timezone
  if (in_array($GLOBALS['db_type'], array(
    'mysql',
    'mysqli',
    'pgsql',
  ))) {
    $offset = '+00:00';
    static $already_set = false;
    if (!$already_set) {
      if ($GLOBALS['db_type'] == 'pgsql') {
        db_query("SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE");
      }
      elseif ($GLOBALS['db_type'] == 'mysqli') {
        db_query("SET @@session.time_zone = '{$offset}'");
      }
      elseif ($GLOBALS['db_type'] == 'mysql' && version_compare(db_version(), '4.1.3', '>=')) {
        db_query("SET @@session.time_zone = '{$offset}'");
      }
      $already_set = true;
    }
  }
  return $timezone;
}