Routine next-run label shows "in 0 hours" just under an hour out
Summary
formatNextRun (the relative "Next run: …" label on routine cards) renders "in 0 hours" for a routine scheduled a little under an hour out (roughly 59.5–60 minutes away).
Problem
What happened: A routine whose next run is ~59 min 45 sec away shows Next run: in 0 hours in RoutineCard.
What I expected: A sensible sub-hour label like in 59 minutes (or in 1 hour) — never a zero-valued hour.
Root cause: In app/src/components/routines/routineHelpers.ts the minute branch rounds but the hour branch floors, and the thresholds don't line up:
const diffMin = Math.round(diffMs / 60_000); // rounds UP to 60 near the hour
if (diffMin < 60) return `in ${diffMin} minute…`;
const diffHrs = Math.floor(diffMs / 3_600_000); // floors to 0 just under an hour
if (diffHrs < 24) return `in ${diffHrs} hour…`; // → "in 0 hours"
For diffMs in [3_570_000, 3_600_000) ms, Math.round(diffMs/60_000) is 60, so the diffMin < 60 guard is false and the minute branch is skipped; the hour branch then floors to 0 → "in 0 hours".
Steps to reproduce:
- Have/seed a routine whose
next_runis ~59 min 45 sec in the future. - Open the routines list; the card shows
Next run: in 0 hours.
Platform: all (pure UI helper); main.
Solution (optional)
Floor the minutes the same way the rest of the helper does, so no value rounds up past its bucket:
const diffMin = Math.floor(diffMs / 60_000);
This keeps diffMin < 60 true for the whole sub-hour range (so ~59.75 min → in 59 minutes), and the hour branch is only reached once diffMs >= 3_600_000 where diffHrs >= 1. Matches the sibling formatTimeAgo in the same file, which already floors throughout.
Acceptance criteria
- [ ] Repro gone — sub-hour routines never render "in 0 hours".
- [ ] Regression safety — unit test added for
formatNextRunaround the 59–60 minute boundary (the helper currently has no test). - [ ] Diff coverage >= 80% — the fix PR meets the changed-lines coverage gate.
Related
Found while auditing routine helpers.
Picking this one up. Going to floor the minutes like the rest of the helper so the just-under-an-hour case reads in minutes instead of in 0 hours, with a unit test around the boundary.