You are here

function date_server_zone_adj in Date 5

Server timezone adjustment.

Used to compute default timezone adjustment made by SQL server so server adjustment can be removed and replaced with correct timezone adjustment values.

Return value

amount in seconds that server adjusts for timezone.

1 call to date_server_zone_adj()
date_sql in ./date.inc
Cross-database date SQL wrapper function allows use of normalized native date functions in both mysql and postgres. Designed to be extensible to other databases.

File

./date.inc, line 1980
Date/time API functions

Code

function date_server_zone_adj() {
  global $db_type;
  static $server_zone_adj;
  if (!isset($server_zone_adj)) {
    switch ($db_type) {
      case 'mysql':
      case 'mysqli':

        // Newest MYSQL versions allow us to set the server to GMT to eliminate adjustments.
        if ($GLOBALS['db_type'] == 'mysqli' || version_compare(mysql_get_server_info(), '4.1.3', '>=')) {
          db_query("SET @@session.time_zone = '+00:00'");
          $server_zone_adj = 0;
        }
        elseif (version_compare(mysql_get_server_info(), '4.1.1', '>=')) {
          $server_zone_adj = db_result(db_query("SELECT UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(UTC_TIMESTAMP())"));
        }
        else {
          $server_zone_adj = date('Z');
        }
        break;
      case 'pgsql':

        // EXTRACT TIMEZONE returns the timezone adjustment in seconds.
        $server_zone_adj = db_result(db_query("SELECT EXTRACT('TIMEZONE' FROM NOW())"));
        break;
    }

    // If no value got set by this point,
    // fall back to using php timezone adjustment as an estimate.
    if (!isset($server_zone_adj)) {
      $server_zone_adj = date('Z');
    }
  }
  return $server_zone_adj;
}