import * as z from "zod"; const CLOCK_TIME = /^([01]\d|2[0-3]):([0-5]\d)$/; /** A 24-hour wall-clock time, e.g. "22:30". */ export const ClockTimeSchema = z.string().regex(CLOCK_TIME, "Use HH:MM"); /** Minutes after midnight for a "HH:MM" time. */ export function clockTimeToMinutes(value: string): number { const match = CLOCK_TIME.exec(value); if (!match) throw new Error("Use HH:MM"); return Number(match[1]) * 60 + Number(match[2]); } /** "HH:MM" for minutes after midnight. */ export function minutesToClockTime(minutes: number): string { const pad = (value: number) => String(value).padStart(2, "0"); return `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}`; }