-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Way back in #3529, ActiveAdmin had an issue where DateTime filter fields were confusing. The main challenge was the wording:
As @timoschilling mentioned (referencing his own image however, not the one above):
With this UI we create a request like ?q[date_lteq]=2014-10-29, put this queries the db with appointments.date <= '2014-10-29 00:00:00', but it should be appointments.date <= '2014-10-29 23:59:59', otherwise it not cover the last date of the range.
This behavior was later fixed / changed in #4504, but then in #8010 it was changed again (back to initial behavior), which @javierjulio did note was a breaking change:
When filtering by range with a datetime column (e.g. created_at), a custom predicate would modify the "to" value so it was always a day after in the generated database query. So if the "from" and "to" filters had the same supplied date, e.g. 2023-07-11, the query would query data in a 24 hour range.
Now that the custom predicate is removed that behavior is not present. To achieve a similar result with this change, the supplied "to" filter value has to be the next day. So going with the earlier example, the "from" is 2023-07-11 and the "to" would now have to be 2023-07-12 instead.
While the workaround provided does indeed work, I don't think it operates by the principle of least surprise -- if the wording of the filter says "Created at less than or equal to 2024-03-01" (emphasis mine), I'd expect the filter to include all entries that have the date 2024-03-01, not just the ones that equal 2024-03-01 00:00:00.
I think this could be mainly fixed via a wording change -- if it instead said "Created at less than or equal to 2024-03-01 00:00:00", I think it would make it at least clear that you would have to add a day to get all the 2024-03-01 entries, and perhaps you wouldn't need to add any special predicates to actually change the searching / filtering behavior.
Expected behavior
When I filter on a datetime field, even when coerced to a date, I expect the resulting entries to include all cases of that date, especially because of the wording "[...] or equal to YYYY-MM-DD".
Actual behavior
Only entries that match YYYY-MM-DD 00:00:00 will be returned for the final date
How to reproduce
Search a datetime filter (e.g. created_at, updated_at) using an ActiveAdmin page.