You are here

function DateSqlHandler::db_tz_support in Date 8

See if the db has timezone name support.

1 call to DateSqlHandler::db_tz_support()
DateSqlHandler::sql_tz in date_api/lib/Drupal/date_api/DateSqlHandler.php
Select a date value from the database, adjusting the value for the timezone.

File

date_api/lib/Drupal/date_api/DateSqlHandler.php, line 39

Class

DateSqlHandler
A class to manipulate date SQL.

Namespace

Drupal\date_api

Code

function db_tz_support($reset = FALSE) {
  $date_api_info = config('date_api.info');
  $has_support = $date_api_info
    ->get('db_tz_support');
  if ($has_support == -1 || $reset) {
    $has_support = FALSE;
    switch ($this->db_type) {
      case 'mysql':
      case 'mysqli':
        $test = db_query("SELECT CONVERT_TZ('2008-02-15 12:00:00', 'UTC', 'US/Central')")
          ->fetchField();
        if ($test == '2008-02-15 06:00:00') {
          $has_support = TRUE;
        }
        break;
      case 'pgsql':
        $test = db_query("SELECT '2008-02-15 12:00:00 UTC' AT TIME ZONE 'US/Central'")
          ->fetchField();
        if ($test == '2008-02-15 06:00:00') {
          $has_support = TRUE;
        }
        break;
    }
    $date_api_info
      ->get('db_tz_support', $has_support)
      ->save();
  }
  return $has_support;
}