katalyst-tables 3.14.0 → 3.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/katalyst/tables/collection/type/date.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd0d472acdcc2f9a6d38866cf22fed2ea5761e032694abd745ccb05050bfb710
|
|
4
|
+
data.tar.gz: 7cdea7b6f28127bd7092f97cf3dd3c3c7c077721802269596261f34cfa0e1048
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b444ae85b2fe77fec493be762e2293910b671ca058ecedb6d679edd08587198382439fe397b7d90fbc35285c05860f5e516dfd5100cc3a109badff67abb75d3
|
|
7
|
+
data.tar.gz: 928a415dfdf4ad9bb1673cbf7f86a674c4e17dc78384f93dff281a9ca19a55e93b5e61c84d5324a93d1d62781707cc7c5350d2ff23df6031c50d5bf7f7b449f6
|
data/CHANGELOG.md
CHANGED
|
@@ -36,6 +36,26 @@ module Katalyst
|
|
|
36
36
|
|
|
37
37
|
private
|
|
38
38
|
|
|
39
|
+
# Dates filtering a datetime column are interpreted as whole days in Time.zone.
|
|
40
|
+
def apply_filter(scope, model, attribute, value)
|
|
41
|
+
return super unless value && datetime_column?(model, attribute.name.split(".").last)
|
|
42
|
+
|
|
43
|
+
scope.where(attribute.name => to_time_range(value))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def datetime_column?(model, column)
|
|
47
|
+
%i[datetime timestamptz].include?(model.type_for_attribute(column).type)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Converts a date or range of dates to an exclusive range of times that
|
|
51
|
+
# covers each day in full, from the start of the first day to the start
|
|
52
|
+
# of the day after the last.
|
|
53
|
+
def to_time_range(value)
|
|
54
|
+
from, to = value.is_a?(::Range) ? [value.begin, value.end] : [value, value]
|
|
55
|
+
|
|
56
|
+
from&.in_time_zone...to&.next_day&.in_time_zone
|
|
57
|
+
end
|
|
58
|
+
|
|
39
59
|
def cast_value(value)
|
|
40
60
|
return value unless value.is_a?(::String)
|
|
41
61
|
|