diff --git a/lib/datagrid/filters/date_filter.rb b/lib/datagrid/filters/date_filter.rb index e8398f4..3557214 100644 --- a/lib/datagrid/filters/date_filter.rb +++ b/lib/datagrid/filters/date_filter.rb @@ -12,8 +12,8 @@ def default_input_options end def apply(grid_object, scope, value) - if value.is_a?(Range) && driver.timestamp_column?(scope, name) - value = value.begin&.beginning_of_day..value.end&.end_of_day + if driver.timestamp_column?(scope, name) + value = Datagrid::Utils.format_date_as_timestamp(value) end super end diff --git a/spec/datagrid/filters/date_filter_spec.rb b/spec/datagrid/filters/date_filter_spec.rb index d42646b..9941b5f 100644 --- a/spec/datagrid/filters/date_filter_spec.rb +++ b/spec/datagrid/filters/date_filter_spec.rb @@ -206,14 +206,14 @@ def entry_dated(date) end end - it "should automatically reverse Array if first more than last" do + it "should automatically reverse if first more than last" do report = test_report(created_at: %w[2013-01-01 2012-01-01]) do scope { Entry } filter(:created_at, :date, range: true) end expect(report.created_at).to eq(Date.new(2012, 0o1, 0o1)..Date.new(2013, 0o1, 0o1)) end - it "should automatically reverse Array if first more than last" do + it "should automatically reverse if first more than last" do report = test_report(created_at: %w[2013-01-01 2012-01-01]) do scope { Entry } filter(:created_at, :date, range: true) @@ -250,4 +250,21 @@ def entry_dated(date) report.created_at = value.as_json expect(report.created_at).to eq(value) end + + it "supports search by timestamp column" do + report = test_report(created_at: Date.today) do + scope {Entry} + filter(:created_at, :date) + end + e1 = Entry.create!(created_at: Date.yesterday + 23.hours) + e2 = Entry.create!(created_at: Date.today.to_time) + e3 = Entry.create!(created_at: Date.today + 12.hours) + e4 = Entry.create!(created_at: Date.today + 23.hours) + e5 = Entry.create!(created_at: Date.tomorrow) + expect(report.assets).to_not include(e1) + expect(report.assets).to include(e2) + expect(report.assets).to include(e3) + expect(report.assets).to include(e4) + expect(report.assets).to_not include(e5) + end end