Skip to content

fix(flags): keep relative date lookbacks inside shorter months - #426

Merged
marandaneto merged 1 commit into
PostHog:mainfrom
luantaraschi:fix/relative-date-month-clamp
Nov 10, 2026
Merged

marandaneto merged 1 commit into
PostHog:mainfrom
luantaraschi:fix/relative-date-month-clamp

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

parseRelativeDate uses time.AddDate for months and years, and AddDate normalizes an impossible date forward. 1m on March 31 lands on March 3 and 1y on 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, and 2m on 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 . and gofmt -l pass in golang:1.24 on 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

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Added a changeset file (written by hand, I didn't run 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 AddDate calls are replaced with two small helpers, and the loop stops once the day is 28 or less.

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.
@luantaraschi
luantaraschi requested a review from a team as a code owner November 9, 2026 07:13

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good; no qualifying findings. Verdict: correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants