Fix calendar-aligned elapsed durations - #376
Draft
francinelucca wants to merge 3 commits into
Draft
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6d8328fd-448c-41bc-8426-102150ede25f
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6d8328fd-448c-41bc-8426-102150ede25f
Contributor
There was a problem hiding this comment.
Pull request overview
Updates elapsed durations to use calendar-aligned month and year anniversaries.
Changes:
- Adds calendar-based duration handling.
- Corrects affected expectations and adds regression cases.
Show a summary per file
| File | Description |
|---|---|
src/duration.ts |
Adds calendar-aligned elapsed-time logic. |
test/duration.ts |
Updates month-duration expectations. |
test/relative-time.js |
Adds month/year regression coverage. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (1)
src/duration.ts:167
- Skipping the time comparison for every span of at least 12 months silently drops lower units even at second or millisecond precision. The added 2022-01-01 10:00 to 2023-01-01 09:00 case is only 364 days and 23 hours, yet this returns exactly
-P1Y. Year spans should also require the time to match at the requested precision, or retain the remainder relative to the calendar anchor.
// Treat matching calendar days at least a year apart as anniversaries even
// when their times differ, rather than leaking fixed-month remainder days.
const isAnniversary = Math.abs(calendarMonths) >= 12
if (!isAnniversary && !hasSameTimeAtPrecision(date, reference, precisionIndex)) return
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6d8328fd-448c-41bc-8426-102150ede25f
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #262.
Testing
npm run build