import { z } from 'zod';
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
function isValidIsoDate(value: string): boolean {
if (!ISO_DATE_REGEX.test(value)) return false;
const [yearPart, monthPart, dayPart] = value.split('-');
const year = Number(yearPart);
const month = Number(monthPart);
const day = Number(dayPart);
const date = new Date(Date.UTC(year, month - 1, day));
return (
date.getUTCFullYear() === year &&
date.getUTCMonth() === month - 1 &&
date.getUTCDate() === day
);
}
export const IsoDateSchema = z
.string()
.refine((value) => isValidIsoDate(value), {
message: 'Invalid date (YYYY-MM-DD)',
});