Repository navigation
fix(flags): stop DateInterval rolling relative dates into the next month - #315
Merged
marandaneto merged 2 commits intoNov 11, 2026
Merged
Conversation
DateInterval normalizes an impossible date forward, so 1m on March 31 landed on March 3 and 1y on February 29 on March 1. Step back one unit at a time and clamp the day after each step, as the SDK spec asks.
Merged
5 of 6 tasks
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.
marandaneto
enabled auto-merge (squash)
November 11, 2026 11:41
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
relativeDateParseForFeatureFlagMatchingsubtracts months and years withDateInterval, and PHP normalizes an impossible date forward.1mon March 31 lands on March 3,1mon May 31 on May 1, and1yon February 29 on March 1. The local evaluator spec subtracts one unit at a time and clamps after every step, so those should be February 28, April 30 and February 28, and2mon March 31 should be January 28 (the spec's own scenario). The same fix was merged for posthog-js (PostHog/posthog-js#5626), posthog-go (PostHog/posthog-go#426) and posthog-python (PostHog/posthog-python#1212).For a flag with an
is_date_after1mcondition evaluated locally on March 31, a person whose date was March 1 or March 2 didn't match.The parser still works in UTC where the spec asks for the team's timezone. I left that alone.
💚 How did you test it?
FeatureFlagLocalEvaluationTest. Nine of them fail onmain.maindiffers in 5,803 of them,1mincluded on 67 days. With this change there are no differences.Client, with the clock frozen at 2025-03-31 and anis_date_after1mcondition. Alast_purchaseof March 1 or March 2 now matches, and February 27 still doesn't.maintoo),phpcswith no new warnings,composer api:check, the adapter tests, andscripts/test-laravel.shfor Laravel 12 and 13.📝 Checklist
If releasing new changes
posthog-php(written by hand, I didn't runpnpm change)🤖 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.
DateIntervalis replaced for months and years with two small helpers built onsetDate. The month loop stops once the day is 28 or less, so it runs at most 11 times whatever the lookback.