You are here

protected function Date::opBetween in Persian Date for Drupal 8 8.4

Filters by operator between.

Parameters

object $field: The views field.

Overrides Date::opBetween

File

src/Plugin/views/filter/Date.php, line 48

Class

Date
Filter to handle dates stored as a timestamp.

Namespace

Drupal\persian_date\Plugin\views\filter

Code

protected function opBetween($field) {

  // if type is offset translate value and delegate handling to parent class
  if ($this->value['type'] == 'offset') {
    $this->value['min'] = OffsetFilterTranslator::translate($this->value['min']);
    $this->value['max'] = OffsetFilterTranslator::translate($this->value['max']);
    parent::opBetween($field);
    return;
  }
  $min = $value = jDateTime::createCarbonFromFormat('Y-m-d H:i:s', $this->value['min'] . ' 00:00:00');
  $max = $value = jDateTime::createCarbonFromFormat('Y-m-d H:i:s', $this->value['max'] . ' 23:59:59');
  $a = intval($min
    ->getTimestamp());
  $b = intval($max
    ->getTimestamp());

  // 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}");
}