Repository navigation
fix(flags): keep relative date lookbacks inside shorter months - #426
Merged
marandaneto merged 1 commit intoNov 10, 2026
Merged
Conversation
time.AddDate normalizes an impossible date forward, so 1m on March 31 landed on March 3 and 1y on February 29 landed on March 1. Step back one unit at a time and clamp the day after each step, as the SDK spec asks.
marandaneto
approved these changes
Nov 10, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
This was referenced Nov 10, 2026
Merged
Merged
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
parseRelativeDateusestime.AddDatefor months and years, andAddDatenormalizes an impossible date forward.1mon March 31 lands on March 3 and1yon February 29 lands on March 1. The local evaluator spec subtracts one unit at a time and clamps after every step, so those should be February 28 and February 28 of the previous year, and2mon March 31 should be January 28. The same fix went up for posthog-js in PostHog/posthog-js#5626.The parser still reads
time.Now()in the local zone where the spec asks for the team's timezone, and I left that alone.💚 How did you test it?
Eight of the twelve new table cases fail with
AddDate. I compared the two helpers against a plain month-by-month loop for every day from 2019 through 2028 (lookbacks 0 to 129, plus 4000 and 9999): 964,392 comparisons, no differences.go test -race -count=1 .,go vet .andgofmt -lpass ingolang:1.24on Linux, the new test passes on Go 1.21, and the three nested modules, which replace this module with../, pass on Go 1.25.📝 Checklist
If releasing new changes
pnpm 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
AddDatecalls are replaced with two small helpers, and the loop stops once the day is 28 or less.