import type { Quiz } from "@/lib/api"; export const KIND_LABEL: Record = { chapter: "Book chapter", lecture: "Lecture", conversation: "Conversation", standalone: "Stand-alone", }; /** * "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 "—"; // 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`; }