function Date::getOffset
Same name in other branches
- 9 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::getOffset()
- 10 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::getOffset()
- 11.x 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
- Date/time views filter.
Namespace
Drupal\datetime\Plugin\views\filterCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.