Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Treat a month as a calendar month when rounding weeks - #409

Open
Goldloli wants to merge 2 commits into
github:mainfrom
Goldloli:fix/last-month-calendar
Open

Goldloli wants to merge 2 commits into
github:mainfrom
Goldloli:fix/last-month-calendar

Conversation

@Goldloli

Copy link
Copy Markdown
Contributor

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 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.

Closes github#406
@Goldloli
Goldloli requested a review from a team as a code owner November 30, 2026 17:01
Copilot AI adaptive review requested due to automatic review settings November 30, 2026 17:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The fallback in src/duration.ts incorrectly reduces an exact four-week duration to three weeks, discarding a full week from the result.

1 open issue
What changed in this PR

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.

Review effort: Balanced (adaptive)

Comment thread src/duration.ts Resolved
@tay1orjones
tay1orjones self-requested a review November 30, 2026 18:01
@Goldloli

Goldloli commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity 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.

1 resolved since last review

Review effort: Max

This branch has not been deployed

No deployments
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.

Incorrect use of "last month"

2 participants