You are here

protected function Date::opBetween in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::opBetween()
  2. 8 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.0 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 97
Contains \Drupal\datetime\Plugin\views\filter\Date.

Class

Date
Date/time views filter.

Namespace

Drupal\datetime\Plugin\views\filter

Code

protected function opBetween($field) {
  $origin = $this->value['type'] == 'offset' ? $this->requestStack
    ->getCurrentRequest()->server
    ->get('REQUEST_TIME') : 0;
  $a = intval(strtotime($this->value['min'], $origin));
  $b = intval(strtotime($this->value['max'], $origin));

  // Formatting will vary on date storage.
  // Convert to ISO format and format for query. UTC timezone is used since
  // dates are stored in UTC.
  $a = $this->query
    ->getDateFormat("'" . $this->dateFormatter
    ->format($a, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE) . "'", $this->dateFormat, TRUE);
  $b = $this->query
    ->getDateFormat("'" . $this->dateFormatter
    ->format($b, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE) . "'", $this->dateFormat, TRUE);

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