/** * A date, or undefined for anything that isn't one — never an Invalid Date. * * Takes `unknown` because that's what a raw record field is: callers shouldn't * have to assert a type they haven't checked yet. Undefined rather than null so * an absent date spreads straight into an optional field, like * `asNonEmptyString` below. */ export function parseDate(value: unknown) { if (typeof value !== 'string') return undefined; const parsed = new Date(value); return isNaN(parsed.getTime()) ? undefined : parsed; } export function asNonEmptyString(value: unknown) { return typeof value === 'string' && value.length > 0 ? value : undefined; }