diff options
Diffstat (limited to 'app/finders/concerns/updated_at_filter.rb')
-rw-r--r-- | app/finders/concerns/updated_at_filter.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/finders/concerns/updated_at_filter.rb b/app/finders/concerns/updated_at_filter.rb new file mode 100644 index 00000000000..0e9a3fb5e8c --- /dev/null +++ b/app/finders/concerns/updated_at_filter.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module UpdatedAtFilter + def by_updated_at(items) + updated_before = params[:updated_before]&.in_time_zone + updated_after = params[:updated_after]&.in_time_zone + return items.none if [updated_before, updated_after].all?(&:present?) && updated_before < updated_after + + items = items.updated_before(updated_before) if updated_before.present? + items = items.updated_after(updated_after) if updated_after.present? + + items + end +end |