Skip to content

Fix ActiveAdmin::Inputs::Filters::DateRangeInput cover last day#4504

Merged
timoschilling merged 1 commit intoactiveadmin:masterfrom
dlackty:3529-fix-date-range-cover-last-day
Jun 30, 2016
Merged

Fix ActiveAdmin::Inputs::Filters::DateRangeInput cover last day#4504
timoschilling merged 1 commit intoactiveadmin:masterfrom
dlackty:3529-fix-date-range-cover-last-day

Conversation

@dlackty
Copy link
Copy Markdown
Contributor

@dlackty dlackty commented Jun 30, 2016

This is a rebased version of #4341 and should close #3529.
Thanks @groony for the work!

@timoschilling
Copy link
Copy Markdown
Member

Thanks to @groony and you

@bartoszkopinski
Copy link
Copy Markdown
Contributor

bartoszkopinski commented Jul 7, 2016

@timoschilling @dlackty I believe this breaks filtering for date fields.
This is a resulting query for range 2016-05-02 - 2016-05-02:

SELECT  1 AS count_column FROM "dates" WHERE ("dates"."starts_on" >= '2016-05-01 23:00:00.000000' AND "dates"."starts_on" < '2016-05-03') LIMIT 30 OFFSET 0

It tries to use date time ranges for date fields resulting in timezone conversion.
Then 2016-05-01 23:00:00.000000 gets downcasted to 2016-05-01 and the results are invalid.

My temporary workaround was to monkeypatch these two methods:

ActiveAdmin::Inputs::Filters::DateRangeInput.class_eval do
  def gt_input_name
    case column.type
    when :date
      "#{method}_gteq"
    else
      "#{method}_gteq_date"
    end
  end

  def lt_input_name
    case column.type
    when :date
      "#{method}_lteq"
    else
      "#{method}_lteq_date"
    end
  end
end

Should I open a separate issue?

@timoschilling
Copy link
Copy Markdown
Member

@bartoszkopinski yes please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Date range filter doesn't cover the last day

3 participants