1 date_sql_handler.inc date_sql_handler::sql_tz($field, $offset = NULL, $comp_date = NULL)

Select a date value from the database, adjusting the value for the timezone.

Check whether database timezone conversion is supported in this system and use it if possible, otherwise use an offset.

Parameters

string $field: The field to be adjusted.

bool $offset: Set a fixed offset or offset field to use for the date. If set, no timezone conversion will be done and the offset will be used.

File

core/modules/date/views/date_sql_handler.inc, line 203
SQL helper for Date API.

Class

date_sql_handler
A class to manipulate date SQL.

Code

function sql_tz($field, $offset = NULL, $comp_date = NULL) {
  // If the timezones are values they need to be quoted, but
  // if they are field names they do not.
  $db_zone = !empty($this->db_timezone_field) ? $this->db_timezone_field : "'{$this->db_timezone}'";
  $localzone = !empty($this->local_timezone_field) ? $this->local_timezone_field : "'{$this->local_timezone}'";
  // If a fixed offset is required, use it.
  if ($offset !== NULL) {
    return $this->sql_offset($field, $offset);
  }
  // If the db and local timezones are the same, make no adjustment.
  elseif ($db_zone == $localzone) {
    return $this->sql_offset($field, 0);
  }
  // If the db has no timezone support, adjust by the offset,
  // could be either a field name or a value.
  elseif (!$this->db_tz_support() || empty($localzone)) {
    if (!empty($this->offset_field)) {
      return $this->sql_offset($field, $this->offset_field);
    }
    else {
      return $this->sql_offset($field, $this->get_offset($comp_date));
    }
  }
  // Otherwise make a database timezone adjustment to the field.
  else {
    return "CONVERT_TZ($field, $db_zone, $localzone)";
  }
}