function Date::opBetween

Same name in this branch
  1. 10 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::opBetween()
Same name in other branches
  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()
  3. 8.9.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::opBetween()
  4. 8.9.x core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::opBetween()
  5. 11.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::opBetween()
  6. 11.x core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date::opBetween()

Overrides NumericFilter::opBetween

1 method overrides Date::opBetween()
Date::opBetween in core/modules/datetime/src/Plugin/views/filter/Date.php
Override parent method, which deals with dates as integers.

File

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

Class

Date
Filter to handle dates stored as a timestamp.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function opBetween($field) {
    $a = intval(strtotime($this->value['min'], 0));
    $b = intval(strtotime($this->value['max'], 0));
    if ($this->value['type'] == 'offset') {
        // Keep sign.
        $a = '***CURRENT_TIME***' . sprintf('%+d', $a);
        // Keep sign.
        $b = '***CURRENT_TIME***' . sprintf('%+d', $b);
    }
    // This is safe because we are manually scrubbing the values.
    // It is necessary to do it this way because $a and $b are formulas when using an offset.
    $operator = strtoupper($this->operator);
    $this->query
        ->addWhereExpression($this->options['group'], "{$field} {$operator} {$a} AND {$b}");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.