Sha256: adfbb11dc9822397a6be10ad1b0cc337f269d5f0084cd836f6c41ab8754c1acf

Contents?: true

Size: 611 Bytes

Versions: 4

Compression:

Stored size: 611 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 format(value)
    return nil if value.blank?
    return value if value.is_a?(Range)
    return value.to_date if value.respond_to?(:to_date)
    return value unless value.is_a?(String)
    #TODO: more smart date normalizer
    Date.parse(value)
  rescue ArgumentError
    nil
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
datagrid-0.8.1 lib/datagrid/filters/date_filter.rb
datagrid-0.8.0 lib/datagrid/filters/date_filter.rb
datagrid-0.7.1 lib/datagrid/filters/date_filter.rb
datagrid-0.7.0 lib/datagrid/filters/date_filter.rb