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>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import type { Quiz } from "@/lib/api";
|
|
|
|
export const KIND_LABEL: Record<Quiz["target_kind"], string> = {
|
|
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`;
|
|
}
|