protected function Date::opSimple in Persian Date for Drupal 8 8.4
Overrides Date::opSimple
File
- src/
Plugin/ views/ filter/ Date.php, line 29
Class
- Date
- Filter to handle dates stored as a timestamp.
Namespace
Drupal\persian_date\Plugin\views\filterCode
protected function opSimple($field) {
// if type is offset translate value and delegate handling to parent class
if (!empty($this->value['type']) && $this->value['type'] == 'offset') {
$this->value['value'] = OffsetFilterTranslator::translate($this->value['value']);
parent::opSimple($field);
return;
}
$min = $value = jDateTime::createCarbonFromFormat('Y-m-d H:i:s', $this->value['value'] . ' 00:00:00');
$max = $value = jDateTime::createCarbonFromFormat('Y-m-d H:i:s', $this->value['value'] . ' 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.
$this->query
->addWhereExpression($this->options['group'], "{$field} BETWEEN {$a} AND {$b}");
}