Skip to content

Commit

Permalink
Merge branch 'main' into version-2
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 14, 2024
2 parents d7f75ba + 82bf828 commit d488792
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/datagrid/filters/date_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions spec/datagrid/filters/date_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit d488792

Please sign in to comment.