You are here

public function availability_calendar_handler_filter_sql_date::op_between in Availability Calendars 7.5

Overrides the parent method to use date only arithmetic and to format the values as ISO dates as accepted and expected by the databases.

Overrides views_handler_filter_date::op_between

File

views/availability_calendar_handler_filter_sql_date.inc, line 24

Class

availability_calendar_handler_filter_sql_date
Defines a filter handler for sql date types.

Code

public function op_between($field) {
  if ($this->value['type'] === 'offset') {

    // Dates relative to now.
    $from = new DateTime('@' . REQUEST_TIME);
    $from
      ->modify($this->value['min']);
    $to = new DateTime('@' . REQUEST_TIME);
    $to
      ->modify($this->value['max']);
  }
  else {

    // Absolute dates.
    $from = new DateTime($this->value['min']);
    $to = new DateTime($this->value['max']);
  }

  // Cut off any time parts and format as ISO date.
  $from
    ->setTime(0, 0, 0);
  $from = $from
    ->format(AC_ISODATE);
  $to
    ->setTime(0, 0, 0);
  $to = $to
    ->format(AC_ISODATE);
  $this->query
    ->add_where_expression($this->options['group'], "{$field} {$this->operator} '{$from}' AND '{$to}'");
}