- Image fields take frameFrom/frameWhen: "Frame at" saves a still from the row's YouTube or Facebook link to /uploads/thumbnails/ (POST /api/admin/video-frame, grabFrame in clips.js). Used on video featured cards. - clock/parseClock moved to src/lib/clock.ts, shared with Video clips. - Newsletter: new drafts no longer store source 'events' (the Pick from select's blank choice), which showed as "events no longer exists"; older drafts load it as blank. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21 lines
962 B
TypeScript
21 lines
962 B
TypeScript
/* Times in a video, as typed and shown: Tools → Video clips and the
|
|
image field's frame picker. */
|
|
|
|
/* 83.5 → "1:23.5"; 3723 → "1:02:03". */
|
|
export function clock(seconds: number | null | undefined): string {
|
|
if (seconds == null || !Number.isFinite(seconds)) return "-";
|
|
const whole = Math.floor(seconds);
|
|
const tenths = Math.round((seconds - whole) * 10);
|
|
const h = Math.floor(whole / 3600);
|
|
const m = Math.floor((whole % 3600) / 60);
|
|
const s = whole % 60;
|
|
const ss = `${String(s).padStart(2, "0")}${tenths ? `.${tenths % 10}` : ""}`;
|
|
return h ? `${h}:${String(m).padStart(2, "0")}:${ss}` : `${m}:${ss}`;
|
|
}
|
|
|
|
/* "1:23.5", "83.5" or "1:02:03" → seconds; null when it isn't a time. */
|
|
export function parseClock(text: string): number | null {
|
|
const parts = text.trim().split(":");
|
|
if (!parts.length || parts.some((p) => !/^\d+(\.\d+)?$/.test(p))) return null;
|
|
return parts.reduce((total, part) => total * 60 + Number(part), 0);
|
|
}
|