The coach rhythm and the quiet hours both parse "HH:MM" wall-clock times and each defined its own ClockTimeSchema, which the contracts index cannot export twice. Both now import it from one module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
20 lines
687 B
TypeScript
20 lines
687 B
TypeScript
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)}`;
|
|
}
|