diff --git a/app/(dashboard)/quizzes/labels.ts b/app/(dashboard)/quizzes/labels.ts index 4749b58..f82db6a 100644 --- a/app/(dashboard)/quizzes/labels.ts +++ b/app/(dashboard)/quizzes/labels.ts @@ -7,11 +7,23 @@ export const KIND_LABEL: Record = { standalone: "Stand-alone", }; -/** "1m 12s" / "8.4s" — response times read better than raw milliseconds. */ +/** + * "8.4s" / "1m 12s" / "3h 20m" / "2d 4h" — response times read better than + * raw milliseconds. Hours past 23h 59m roll up into days. Mirrors fmtMs in + * the app's quiz-result-view.tsx. + */ export function fmtMs(ms: number | null | undefined): string { if (ms == null) return "—"; - if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`; - const m = Math.floor(ms / 60_000); - const s = Math.round((ms % 60_000) / 1000); + // Below 59.95s: one decimal place (anything higher would print "60.0s"). + if (ms < 59_950) return `${(ms / 1000).toFixed(1)}s`; + // Whole seconds from here, so rounding can't print "1m 60s". + const total = Math.round(ms / 1000); + const d = Math.floor(total / 86_400); + const h = Math.floor((total % 86_400) / 3600); + const m = Math.floor((total % 3600) / 60); + const s = total % 60; + // The two largest units: 2d 4h · 3h 20m · 12m 5s. + if (d > 0) return `${d}d ${h}h`; + if (h > 0) return `${h}h ${m}m`; return `${m}m ${s}s`; }