Skip to content

Correctly round same-month day durations#361

Open
thazhemadam wants to merge 1 commit into
github:mainfrom
thazhemadam:fix-day-month-rounding
Open

Correctly round same-month day durations#361
thazhemadam wants to merge 1 commit into
github:mainfrom
thazhemadam:fix-day-month-rounding

Conversation

@thazhemadam

Copy link
Copy Markdown

Summary

Avoid rounding same-calendar-month spans like 25 or 26 days to one month via the intermediate 4-week representation.

Before this change, relative durations could move backward in precision around the month boundary:

25 days -> last month
26 days -> last month
27 days -> 27 days ago
28 days -> 28 days ago

After this change, day-only spans remain in days until they cross the calendar-month boundary.

Test plan

  • npm test

@thazhemadam thazhemadam requested a review from a team as a code owner June 29, 2026 18:14
@thazhemadam thazhemadam force-pushed the fix-day-month-rounding branch from 6478524 to 48e1b9c Compare June 29, 2026 18:16
@thazhemadam thazhemadam changed the title Fix same-month duration rounding Correctly round same-month day durations Jun 29, 2026
Relative date labels around the month boundary can currently move
backward in precision: a 25-day-old timestamp may render as "last month"
while a 27-day-old timestamp renders as "27 days ago". In sorted date
lists this makes newer items look older than later rows, even when the
underlying timestamps are ordered correctly.

Keep same-calendar-month day spans in days instead of promoting them
through the intermediate four-week representation to one month. Preserve
month rounding once the compared dates cross a calendar-month boundary.

Add regression coverage for the 25/26-day same-month cases so the labels
remain monotonic around the month boundary.

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.

Pull request overview

This PR refines roundToSingleUnit’s day/week/month rounding so that same-calendar-month spans (e.g., 25–26 days) don’t get converted into “1 month” via an intermediate “4 weeks” rounding step, improving consistency around month boundaries.

Changes:

  • Adjusted rounding logic to prevent day-only, same-month spans from being rounded into 4 weeks (and then into 1 month).
  • Updated roundToSingleUnit test expectations to keep same-month ~25-day spans in days.
  • Added getRelativeTimeUnit test cases to cover same-month negative and positive day spans near the 25–26 day range.
Show a summary per file
File Description
src/duration.ts Updates the week-rounding condition to avoid same-month 4-week→month conversion for day-only spans.
test/duration.ts Updates and extends tests to validate that same-month 25–26 day durations remain expressed in days.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

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