const readable = (iso?: string) => { if (!iso) return undefined; const at = new Date(iso); return Number.isNaN(at.getTime()) ? undefined : at; }; const clock = (at: Date) => at.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" }); const daysBefore = (at: Date) => { const midnight = (day: Date) => new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime(); return Math.round((midnight(new Date()) - midnight(at)) / 86_400_000); }; /** "today, 8:05 AM", "yesterday, 4:20 PM" or "9/24/2026, 8:05 AM". */ export const dayAndTime = (iso?: string): string | undefined => { const at = readable(iso); if (!at) return undefined; const ago = daysBefore(at); const day = ago === 0 ? "today" : ago === 1 ? "yesterday" : at.toLocaleDateString("en-US"); return `${day}, ${clock(at)}`; }; /** A row on the bench is today's work, so today reads as the time alone. */ export const benchTime = (iso?: string): string | undefined => { const at = readable(iso); if (!at) return undefined; return daysBefore(at) === 0 ? clock(at) : dayAndTime(iso); }; export const capitalized = (text: string) => text.charAt(0).toUpperCase() + text.slice(1);