Repository navigation
fix(flags): clamp the day after every step in relative month lookbacks - #356
Merged
marandaneto merged 1 commit intoNov 11, 2026
Merged
Conversation
prev_month(n) and prev_year(n) jump in one go and clamp the day once, so 2m on March 31 landed on January 31 and 4y on February 29, 2024 on February 29, 2020. Step back one unit at a time while the day can still clamp, as the SDK spec asks.
marandaneto
approved these changes
Nov 11, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
relative_date_parse_for_feature_flag_matchingusesprev_month(n)andprev_year(n), which jump in one go and clamp the day once at the end. The local evaluator spec subtracts one unit at a time and clamps after every step, so2mon March 31 should be January 28 (the spec's own scenario) rather than January 31, and4yon February 29, 2024 should be February 28, 2020.1mand1yalready match the spec. The same change was merged for posthog-python (PostHog/posthog-python#1212), posthog-js (PostHog/posthog-js#5626) and posthog-go (PostHog/posthog-go#426), and is open for posthog-php (PostHog/posthog-php#315).For a flag with an
is_date_after2mcondition evaluated locally on March 31, a person whose date was January 29 to 31 matched.The parser still works in UTC where the spec asks for the team's timezone. I left that alone.
💚 How did you test it?
feature_flag_spec.rb. Four of them fail onmain(2mand13mfrom March 31,12mfrom January 29,4yfrom February 29).maindiffers in 5,111 of them, all with a lookback of two or more units. With this change there are no differences.PostHog::Client, with the clock frozen at 2025-03-31 and anis_date_after2mcondition. Alast_purchaseof January 29 no longer matches, February 1 still does and January 27 still doesn't.bundle exec rspecon Ruby 3.2, 3.3 and 3.4 (2502 examples, 0 failures),bundle exec rubocopandbundle exec rake public_api:check.📝 Checklist
If releasing new changes
posthog-ruby(written by hand, I didn't runpnpm changeset)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Luan Taraschi directed the work and reviewed the diff. Claude Code (Claude Opus 5.5) wrote the change and ran the checks. The loop steps one month at a time only while the day is above 28 and then does the rest with a single
prev_month, so it runs at most 11 times whatever the lookback. Years take one step and then one jump, since only February 29 can clamp.