Same name and namespace in other branches
  1. 8.9.x core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::getOffset()
  2. 9 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::getOffset()

Get the proper offset from UTC to use in computations.

Parameters

string $time: A date/time string compatible with \DateTime. It is used as the reference for computing the offset, which can vary based on the time zone rules.

string $timezone: The time zone that $time is in.

Return value

int The computed offset in seconds.

2 calls to Date::getOffset()
Date::opBetween in core/modules/datetime/src/Plugin/views/filter/Date.php
Override parent method, which deals with dates as integers.
Date::opSimple in core/modules/datetime/src/Plugin/views/filter/Date.php
Override parent method, which deals with dates as integers.

File

core/modules/datetime/src/Plugin/views/filter/Date.php, line 170

Class

Date

Namespace

Drupal\datetime\Plugin\views\filter

Code

protected function getOffset($time, $timezone) {

  // Date-only fields do not have a time zone or offset from UTC associated
  // with them. For relative (i.e. 'offset') comparisons, we need to compute
  // the user's offset from UTC for use in the query.
  $origin_offset = 0;
  if ($this->dateFormat === DateTimeItemInterface::DATE_STORAGE_FORMAT && $this->value['type'] === 'offset') {
    $origin_offset = $origin_offset + timezone_offset_get(new \DateTimeZone(date_default_timezone_get()), new \DateTime($time, new \DateTimeZone($timezone)));
  }
  return $origin_offset;
}