Quiz times: show hours and days

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 <noreply@anthropic.com>
This commit is contained in:
gosangam
2026-10-18 14:29:05 +05:30
co-authored by Claude Opus 5.5
parent a63c329850
commit 770d465fef
+16 -4
View File
@@ -7,11 +7,23 @@ export const KIND_LABEL: Record<Quiz["target_kind"], string> = {
standalone: "Stand-alone", 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 { export function fmtMs(ms: number | null | undefined): string {
if (ms == null) return "—"; if (ms == null) return "—";
if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`; // Below 59.95s: one decimal place (anything higher would print "60.0s").
const m = Math.floor(ms / 60_000); if (ms < 59_950) return `${(ms / 1000).toFixed(1)}s`;
const s = Math.round((ms % 60_000) / 1000); // 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`; return `${m}m ${s}s`;
} }