weathercock 1.2.0 → 1.3.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: e6f2f450b510bee3dbea48bf0b4e7e37ef24040d82141caaabe45d6dce3c3cb6
4
- data.tar.gz: ab78b22090a84493d97b3f5deca74963f150d3ea21af0b47408babb64fdb7985
3
+ metadata.gz: c3e7d0d33ec97370a0ec3fadd5c5660ed904fac4d53ac61b4f15f2ef896d86a0
4
+ data.tar.gz: 4afa58c886959543dcff63c906be312e2e89997aef099d48bea71a00c117696c
5
5
  SHA512:
6
- metadata.gz: e10e7fee6c2e629c994c097920af3226a3f6fdde65a18aed9a85b5556ae6d0a4b4abf78029b833d50d88581745f2517911177ebaee78bbe7de6aef2c78eacb49
7
- data.tar.gz: 4a2089ecaceb03a54cb1462504f9b946145b81837db87c4a497650164180c56533246f851ab0c1e1c8f84a337f06faf767c782960e8a9ac6273149f0e69f5766
6
+ metadata.gz: e81b1b7dc020df60de5d0cc9428ea8816f8b8fbfe90c7b8f5a32e195356579e29205b32beab2633e912d87b0fe4e9a57fb3b573974666d74d8ea7df671fb09ab
7
+ data.tar.gz: 81a3b745b52805b80977c8e36e0502c606bf94142feb14d6b30ae87c5563a1fcd7e0c18067fe70ee878ec2de0326d8ba331fc9fe793c71317f28f104bed2c780
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.3.0 - 2026-09-18
4
+
5
+ ### Changed
6
+
7
+ - Time-bucketed keys now prefer `Time.current` (when ActiveSupport is loaded) over `Time.now`, so bucket boundaries follow the application's configured time zone instead of each host's TZ
8
+
9
+ ### Fixed
10
+
11
+ - Daily window keys are now built by calendar-day arithmetic; elapsed-seconds arithmetic could skip a date around a DST transition
12
+
3
13
  ## v1.2.0 - 2026-09-16
4
14
 
5
15
  ### Changed
data/README.md CHANGED
@@ -21,6 +21,10 @@ Weathercock.configure do |c|
21
21
  end
22
22
  ```
23
23
 
24
+ ### Time zone
25
+
26
+ Time-bucketed keys are built from `Time.current` when it is available (i.e. ActiveSupport is loaded), so in a Rails app bucket boundaries follow `config.time_zone` regardless of each host's `TZ` setting. Outside Rails, `Time.now` (system time zone) is used.
27
+
24
28
  ### Tracking
25
29
 
26
30
  Include `Weathercock::Scorable` in any class that has an `id`:
@@ -26,12 +26,16 @@ module Weathercock
26
26
  end
27
27
 
28
28
  def window_keys(base, type, count)
29
- now = Time.now
29
+ # Time.current (ActiveSupport) follows the app-configured time zone, so
30
+ # bucket boundaries do not depend on each host's TZ setting.
31
+ now = Time.respond_to?(:current) ? Time.current : Time.now # steep:ignore NoMethod
30
32
  case type
31
33
  when :hours
32
34
  count.times.map { |i| bucket(base, type, now - (i * 3600)) }
33
35
  when :days
34
- count.times.map { |i| bucket(base, type, now - (i * 86400)) }
36
+ # now - i * 86400 would skip a date around a DST transition
37
+ today = now.to_date
38
+ count.times.map { |i| bucket(base, type, today - i) }
35
39
  when :months
36
40
  d = Date.new(now.year, now.month)
37
41
  count.times.map { |i| bucket(base, type, d << i) }
@@ -16,7 +16,9 @@ module Weathercock
16
16
  end
17
17
 
18
18
  def hit(id, event, increment: 1)
19
- now = Time.now
19
+ # Time.current (ActiveSupport) follows the app-configured time zone, so
20
+ # bucket boundaries do not depend on each host's TZ setting.
21
+ now = Time.respond_to?(:current) ? Time.current : Time.now # steep:ignore NoMethod
20
22
  base = @key_builder.base(event)
21
23
 
22
24
  @redis.pipelined do |p|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weathercock
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weathercock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takafumi ONAKA