Class: Datagrid::Filters::DateFilter

Inherits:
BaseFilter show all
Includes:
RangedFilter
Defined in:
lib/datagrid/filters/date_filter.rb

Instance Attribute Summary

Attributes inherited from BaseFilter

#block, #grid_class, #name, #options

Instance Method Summary collapse

Methods included from RangedFilter

#initialize, #parse_values, #range?

Methods inherited from BaseFilter

#allow_blank?, #allow_nil?, #default, #default_filter_block, #dummy?, #enabled?, #form_builder_helper_name, form_builder_helper_name, #header, #initialize, #multiple?, #parse_values, #separator, #supports_range?, #type, #unapplicable_value?

Instance Method Details

#apply(grid_object, scope, value) ⇒ Object


7
8
9
10
11
12
# File 'lib/datagrid/filters/date_filter.rb', line 7

def apply(grid_object, scope, value)
  if value.is_a?(Range)
    value = value.first.beginning_of_day..value.last.end_of_day
  end
  super(grid_object, scope, value)
end

#default_filter_where(scope, value) ⇒ Object


27
28
29
30
31
32
# File 'lib/datagrid/filters/date_filter.rb', line 27

def default_filter_where(scope, value)
  if driver.is_timestamp?(scope, name)
    value = Datagrid::Utils.format_date_as_timestamp(value)
  end
  super(scope, value)
end

#format(value) ⇒ Object


19
20
21
22
23
24
25
# File 'lib/datagrid/filters/date_filter.rb', line 19

def format(value)
  if formats.any? && value
    value.strftime(formats.first)
  else
    super
  end
end

#parse(value) ⇒ Object


14
15
16
# File 'lib/datagrid/filters/date_filter.rb', line 14

def parse(value)
  Datagrid::Utils.parse_date(value)
end