You are here

protected function Date::opBetween in Drupal 9

Same name in this branch
  1. 9 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::opBetween()
  2. 9 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::opBetween()
Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::opBetween()

Override parent method, which deals with dates as integers.

Overrides Date::opBetween

File

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

Class

Date
Date/time views filter.

Namespace

Drupal\datetime\Plugin\views\filter

Code

protected function opBetween($field) {
  $timezone = $this
    ->getTimezone();
  $origin_offset = $this
    ->getOffset($this->value['min'], $timezone);

  // Although both 'min' and 'max' values are required, default empty 'min'
  // value as UNIX timestamp 0.
  $min = !empty($this->value['min']) ? $this->value['min'] : '@0';

  // Convert to ISO format and format for query. UTC timezone is used since
  // dates are stored in UTC.
  $a = new DateTimePlus($min, new \DateTimeZone($timezone));
  $a = $this->query
    ->getDateFormat($this->query
    ->getDateField("'" . $this->dateFormatter
    ->format($a
    ->getTimestamp() + $origin_offset, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE) . "'", TRUE, $this->calculateOffset), $this->dateFormat, TRUE);
  $b = new DateTimePlus($this->value['max'], new \DateTimeZone($timezone));
  $b = $this->query
    ->getDateFormat($this->query
    ->getDateField("'" . $this->dateFormatter
    ->format($b
    ->getTimestamp() + $origin_offset, 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE) . "'", TRUE, $this->calculateOffset), $this->dateFormat, TRUE);

  // This is safe because we are manually scrubbing the values.
  $operator = strtoupper($this->operator);
  $field = $this->query
    ->getDateFormat($this->query
    ->getDateField($field, TRUE, $this->calculateOffset), $this->dateFormat, TRUE);
  $this->query
    ->addWhereExpression($this->options['group'], "{$field} {$operator} {$a} AND {$b}");
}