You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Treat a month as a calendar month when rounding weeks - #409
Description: A month is a calendar month, but rounding four weeks up to a month never checked the calendar. Twenty-five and twenty-six days round up to four weeks, so a date that is still in the current month was reported as "last month". On 2026-11-28, both 2026-11-03 and 2026-11-02 rendered "last month", while 2026-11-01 rendered "27 days ago".
This only promotes weeks to a month when the calendar month actually changed, so a date inside the current month stays in weeks. Four weeks is not a month either, so that case no longer rounds up. Bare durations without an exact date keep the previous approximation, since they carry no calendar anchor.
npm test passes: 721 tests in 6 files, including the 7 added below.
New cases in test/duration.ts cover 25, 26, 27, 28 and 29 days before 2026-11-28, a bare P25D duration, and a P28D span that really did cross into October.
A/B against main: with the source change reverted, the same run renders -1 month for 25, 26 and 28 days; with it, 25 and 26 days render -3 week and 28 days renders -1 month.
The added cases use timeZone: 'UTC' so the boundaries do not depend on the machine's zone. On a UTC+8 machine the same instants land on 11-04 and 11-03 rather than 11-03 and 11-02, which is a separate, existing local-time behaviour of the day counter this change does not touch.
"Last month" is a calendar concept, but rounding four weeks up to a month never
checked the calendar. Twenty-five and twenty-six days round up to four weeks, so
a date that is still in the current month was reported as "last month": on
2026-11-28, 2026-11-03 and 2026-11-02 both rendered that way while 2026-11-01
rendered "27 days ago".
Only promote weeks to a month when the calendar month actually changed. A date
in the current month keeps three weeks, which is what the same date already
renders once it is a few days younger. Four weeks is not a month either, so that
case no longer rounds up to four weeks. Bare durations without a date keep the
previous approximation.
Closesgithub#406
This PR addresses #406 by checking calendar-month boundaries before promoting rounded weeks to months, preventing same-month dates from being labeled “last month.”
Changes:
Adds time-zone-aware calendar-month comparison for date-anchored rounding.
Preserves approximate month conversion for durations without an exact date.
Adds seven regression cases covering late-November dates and bare-duration behavior.
File
Description
test/duration.ts
Adds calendar-boundary and bare-duration regression tests.
src/duration.ts
Gates week-to-month promotion on calendar-month changes.
Fixed in e6c2215: derived the same-month week fallback from Math.floor(calendarDaysBetween(...) / 7) so 25–26 days stay at 3 weeks while an exact 28-day (-P4W) span stays 4 weeks. Added regression test; lint, build, and 722 tests pass.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The test leaves the new cross-month week-promotion branch untested because P28D is converted to a month earlier, and its positive duration conflicts with the supplied past date.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Test does not exercise cross-month week promotion
test/duration.ts:637
P28D becomes a month in the earlier calendar-date logic, so this test never exercises the new cross-month week-promotion branch. Its positive duration also conflicts with the supplied past date. Use -P25D from November 25 to October 31, expecting -P1M, to cover promotion when the calendar month differs.
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
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.
Description: A month is a calendar month, but rounding four weeks up to a month never checked the calendar. Twenty-five and twenty-six days round up to four weeks, so a date that is still in the current month was reported as "last month". On 2026-11-28, both 2026-11-03 and 2026-11-02 rendered "last month", while 2026-11-01 rendered "27 days ago".
This only promotes weeks to a month when the calendar month actually changed, so a date inside the current month stays in weeks. Four weeks is not a month either, so that case no longer rounds up. Bare durations without an exact date keep the previous approximation, since they carry no calendar anchor.
Link to tracking Issue(s):
Testing:
npm testpasses: 721 tests in 6 files, including the 7 added below.test/duration.tscover 25, 26, 27, 28 and 29 days before 2026-11-28, a bareP25Dduration, and aP28Dspan that really did cross into October.main: with the source change reverted, the same run renders-1 monthfor 25, 26 and 28 days; with it, 25 and 26 days render-3 weekand 28 days renders-1 month.timeZone: 'UTC'so the boundaries do not depend on the machine's zone. On a UTC+8 machine the same instants land on 11-04 and 11-03 rather than 11-03 and 11-02, which is a separate, existing local-time behaviour of the day counter this change does not touch.