Skip to content

fix(rules): carry the year when adding relative months - #53

Merged
olebedev merged 1 commit into
olebedev:masterfrom
SahilRajputdotexe:fix/relative-months-year-rollover
Oct 14, 2026
Merged

olebedev merged 1 commit into
olebedev:masterfrom
SahilRajputdotexe:fix/relative-months-year-rollover

Conversation

@SahilRajputdotexe

Copy link
Copy Markdown
Contributor

Problem

The deadline and past time rules compute the target month as (ref.Month() ± n) % 12, so the year is never carried. With 6 October 2016 as the reference date:

input got expected
in 2 months 2015-12-06 2016-12-06
in 3 months 2016-01-06 2017-01-06
within half a year 2016-04-06 2017-04-06

14 months ago goes wrong the same way in the other direction.

Fix

Drop the modulo and let time.Date normalize the month. Context.Time already relies on that, and the zh rules pass an unreduced month too.

The change is applied to the en, nl, br and ru rules. Tests are added for en with reference dates that cross a year boundary.

The deadline and past time rules reduced the target month modulo 12, so
the year was never carried: with a reference date in October, "in 3
months" resolved to January of the same year, and "in 2 months" to
December of the previous one.

Drop the modulo and let time.Date normalize the month, which is what
Context.Time already relies on.

@olebedev olebedev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed relative-month year carry and compatibility with current month-end clamping. Tests and go vet pass on this PR combined with master after PR #55 (Go 1.26.7).

@olebedev
olebedev merged commit 409098d into olebedev:master Oct 14, 2026
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