From 770d465fefcee2a6971781bc825224ea52e5aa02 Mon Sep 17 00:00:00 2001 From: gosangam Date: Sun, 18 Oct 2026 14:29:05 +0530 Subject: [PATCH] Quiz times: show hours and days MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Participant and response times roll up into hours, then days past 23h 59m (3h 20m, 2d 4h) — a two-day attempt read "2880m 0s" before. Co-Authored-By: Claude Opus 5.5 --- app/(dashboard)/quizzes/labels.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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`; }