You are here

public function date_sql_handler::db_tz_support in Date 7.2

Same name and namespace in other branches
  1. 5.2 date_api_sql.inc \date_sql_handler::db_tz_support()
  2. 6.2 date_api_sql.inc \date_sql_handler::db_tz_support()
  3. 6 date_api_sql.inc \date_sql_handler::db_tz_support()
  4. 7.3 date_api/date_api_sql.inc \date_sql_handler::db_tz_support()
  5. 7 date_api/date_api_sql.inc \date_sql_handler::db_tz_support()

See if the db has timezone name support.

1 call to date_sql_handler::db_tz_support()
date_sql_handler::sql_tz in date_api/date_api_sql.inc
Select a date value from the database, adjusting for the timezone.

File

date_api/date_api_sql.inc, line 119
SQL helper for Date API.

Class

date_sql_handler
A class to manipulate date SQL.

Code

public function db_tz_support($reset = FALSE) {
  $has_support = variable_get('date_db_tz_support', -1);
  if ($has_support == -1 || $reset) {
    $has_support = FALSE;
    switch ($this->db_type) {
      case 'mysql':
        $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':

        // PostgreSQL doesn't always have timezone support enabled, so catch
        // exceptions so they don't break the site. This is safe to do as it
        // is only checking to see if timezones are actually supported.
        try {
          $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;
          }
        } catch (PDOException $e) {

          // No support.
        }
        break;
    }
    variable_set('date_db_tz_support', $has_support);
  }
  return $has_support;
}