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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 544768f007ab3f12b3cbbba816479f12d3592eb31bf36789097edf3208c88517
4
- data.tar.gz: 47d084766c55f247991c78aa86d83348e5f28db9f189510aba144fd7c7e5158d
3
+ metadata.gz: bd0d472acdcc2f9a6d38866cf22fed2ea5761e032694abd745ccb05050bfb710
4
+ data.tar.gz: 7cdea7b6f28127bd7092f97cf3dd3c3c7c077721802269596261f34cfa0e1048
5
5
  SHA512:
6
- metadata.gz: 749e2a3c9e39822f2349e16a15e58aa71b248ebd72fcd7f9b5f996acba68cad767d0b92432a43f5c942576a617a0c506798a289d2ff5a57898f204cc0685280d
7
- data.tar.gz: 7c607a4c47c772835fde2ded77c383d9cbdb3a3245d401dfc406ab94b52963cb1976af773449a4db24acf55848dbe73b81d9836bd694ddb617f083a28bb80514
6
+ metadata.gz: 4b444ae85b2fe77fec493be762e2293910b671ca058ecedb6d679edd08587198382439fe397b7d90fbc35285c05860f5e516dfd5100cc3a109badff67abb75d3
7
+ data.tar.gz: 928a415dfdf4ad9bb1673cbf7f86a674c4e17dc78384f93dff281a9ca19a55e93b5e61c84d5324a93d1d62781707cc7c5350d2ff23df6031c50d5bf7f7b449f6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [3.15.0]
2
+
3
+ * Date filters on datetime columns now match whole days in `Time.zone`, including the last day of a range (#169)
4
+
1
5
  ## [3.14.0]
2
6
 
3
7
  * Support for ordering collections sorted `ordinal desc`
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.0
4
+ version: 3.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive