posthog-ruby 3.32.1 → 3.32.2

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: 6f3617315bd23ae3b6cbce6213b21cbc10cb83db1dfc6a0c111d5f94404088cc
4
- data.tar.gz: 47b81c9ce5aef958562908d9687d7ef95d89ae675692f3e8f3f1583857298959
3
+ metadata.gz: 3056f1b2b68fc770ad5d18e659f34d6d992baaee102184e0f4a6d8b7fae3758c
4
+ data.tar.gz: 102c9721a7e7a99616948dbcd9486e4e6931d10eea192eff9c69f7cf7468416f
5
5
  SHA512:
6
- metadata.gz: 493420b17402e4d2bbdd0cbc9dea605cd23921f07b89e15e5c048c724a184b86f3c1b43c6989b60e9875801fd598c264523ed46d8a5a1710af53dacbef5c52e2
7
- data.tar.gz: 6a9efff5883c666fcb1df41163eee04af68f1b5c69e03c551b262d0fec0fbede69fdc3f5f0af703f72043b5e259c214535b72d1ebaefaeb015f1202aeb29c7cf
6
+ metadata.gz: 04d40769af7139d68a82052011107f43467aab48472b2747b1bb770c6e83f77404cdea25c718ec0db518cbdabd17e40fca96af7ca7e39c750fd9fc2f6e150efa
7
+ data.tar.gz: 2e9ef0c1931fda12ca37059632dd8d6e30eb889b9982c542e685b1846e1555daa26b638947daa0c7defb5ee1ebf0508d8d673b099ccbe37d5cba6c51a035d84f
@@ -548,9 +548,9 @@ module PostHog
548
548
  when 'w'
549
549
  parsed_dt = parsed_dt.prev_day(number * 7)
550
550
  when 'm'
551
- parsed_dt = parsed_dt.prev_month(number)
551
+ parsed_dt = subtract_months(parsed_dt, number)
552
552
  when 'y'
553
- parsed_dt = parsed_dt.prev_year(number)
553
+ parsed_dt = subtract_years(parsed_dt, number)
554
554
  else
555
555
  return nil
556
556
  end
@@ -558,6 +558,30 @@ module PostHog
558
558
  parsed_dt
559
559
  end
560
560
 
561
+ # Steps back one month at a time and clamps the day after every step, as the
562
+ # SDK spec requires: March 31 minus two months is January 28. A single
563
+ # prev_month(2) clamps once and lands on January 31.
564
+ def self.subtract_months(date_time, months)
565
+ steps = 0
566
+ # Every month has at least 28 days, so once the day is 28 or less no step
567
+ # can clamp it again and the rest can be done in one jump.
568
+ while steps < months && date_time.day > 28
569
+ date_time = date_time.prev_month
570
+ steps += 1
571
+ end
572
+ date_time.prev_month(months - steps)
573
+ end
574
+ private_class_method :subtract_months
575
+
576
+ # Years work the same way. Only February 29 can clamp, and only on the first
577
+ # step, so one step followed by a single jump matches stepping every year.
578
+ def self.subtract_years(date_time, years)
579
+ return date_time if years.zero?
580
+
581
+ date_time.prev_year.prev_year(years - 1)
582
+ end
583
+ private_class_method :subtract_years
584
+
561
585
  # Parse a single semver numeric identifier, rejecting empty, non-digit, or
562
586
  # leading-zero values per semver 2.0.0 §2. `reason` names the owner of the value:
563
587
  # UNSUPPORTED_DEFINITION for a filter value, MISSING_CONTEXT for a value the call passed.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.32.1'
4
+ VERSION = '3.32.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.32.1
4
+ version: 3.32.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''