Skip to content

fix(timer): carry rounded minutes into the hour in humanDuration - #447

Merged
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/human-duration-minute-carry
Aug 29, 2026
Merged

fix(timer): carry rounded minutes into the hour in humanDuration#447
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/human-duration-minute-carry

Conversation

@clawedassistant26

Copy link
Copy Markdown
Contributor

What

humanDuration() in src/timer.mjs derives hours and minutes independently from the raw seconds:

const h = Math.floor(total / 3600);
const m = Math.round((total % 3600) / 60);

When the sub-hour remainder is in the last 30 seconds of a minute-that-completes-the-hour, m rounds up to 60 while h has not been incremented, so the output shows 60m, 1h 60m or 23h 60m instead of carrying into the hour.

Reproduce (before)

humanDuration(3599)  => "60m"      (want "1h")
humanDuration(7199)  => "1h 60m"   (want "2h")
humanDuration(86399) => "23h 60m"  (want "24h")
humanDuration(3570)  => "60m"      (want "1h")

This is user-facing in /timer off, /timer status and /timer log totals — a time-tracking surface that renders e.g. 1h59m59s as "1h 60m".

Fix

Round to whole minutes first, then split once so the carry happens in one place:

const minutes = Math.round(total / 60);
const h = Math.floor(minutes / 60);
const m = minutes % 60;

Tests

Added regression cases in test/timer.test.mjs (3599→1h, 3570→1h, 3569→59m, 7199→2h, 86399→24h). Reverting only the src/timer.mjs change fails exactly that one test; with the fix all timer tests pass. Full suite: 2277 pass / 0 fail / 337 skip.

humanDuration derived hours and minutes independently from the raw
seconds, so a sub-hour remainder that rounds up to 60 minutes printed as
"60m", "1h 60m" or "23h 60m" instead of carrying into the hour it
belongs in. Any tracked stretch in the last 30 seconds of an hour (e.g.
1h59m59s) rendered wrong in /timer off, /timer status and /timer log
totals.

Round to whole minutes first, then split into hours and minutes so the
carry happens once. Add regression cases for the boundary.
@ralyodio
ralyodio merged commit eb213be into moshcoder:main Aug 29, 2026
6 checks passed
@ralyodio ralyodio mentioned this pull request Aug 29, 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.

3 participants