Sha256: 67af67fc3922f9449f807daac9f612f795213bc7d796036b74d83363e9aaa23c

Contents?: true

Size: 788 Bytes

Versions: 20

Compression:

Stored size: 788 Bytes

Contents

require "datagrid/filters/ranged_filter"

class Datagrid::Filters::DateFilter < Datagrid::Filters::BaseFilter

  include RangedFilter

  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

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


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

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

  protected

  def formats
    Array(Datagrid.configuration.date_formats)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
datagrid-1.3.7 lib/datagrid/filters/date_filter.rb
datagrid-1.3.6 lib/datagrid/filters/date_filter.rb
datagrid-1.3.5 lib/datagrid/filters/date_filter.rb
datagrid-1.3.4 lib/datagrid/filters/date_filter.rb
datagrid-1.3.3 lib/datagrid/filters/date_filter.rb
datagrid-1.3.2 lib/datagrid/filters/date_filter.rb
datagrid-1.3.1 lib/datagrid/filters/date_filter.rb
datagrid-1.3.0 lib/datagrid/filters/date_filter.rb
datagrid-1.2.3 lib/datagrid/filters/date_filter.rb
datagrid-1.2.2 lib/datagrid/filters/date_filter.rb
datagrid-1.2.1 lib/datagrid/filters/date_filter.rb
datagrid-1.2.0 lib/datagrid/filters/date_filter.rb
datagrid-1.1.2 lib/datagrid/filters/date_filter.rb
datagrid-1.1.1 lib/datagrid/filters/date_filter.rb
datagrid-1.1.0 lib/datagrid/filters/date_filter.rb
datagrid-1.0.5 lib/datagrid/filters/date_filter.rb
datagrid-1.0.4 lib/datagrid/filters/date_filter.rb
datagrid-1.0.3 lib/datagrid/filters/date_filter.rb
datagrid-1.0.2 lib/datagrid/filters/date_filter.rb
datagrid-1.0.1 lib/datagrid/filters/date_filter.rb