- add normalizeAiDateString() to coerce bare ISO datetimes, date-only strings, and fractional-second variants into offset-aware format - apply via z.preprocess in AiEventResponseItemSchema so Zod validation no longer rejects AI responses missing a timezone offset - fix system prompt to use toISOString() (unambiguous UTC) and clarify expected datetime format for the AI model - install bun-types and add to tsconfig so bun:test resolves cleanly - add 8 behaviour-driven tests covering all normalizer edge cases
11 lines
330 B
TypeScript
11 lines
330 B
TypeScript
import { formatISO, parseISO } from "date-fns";
|
|
|
|
const ISO_DATETIME_WITH_OFFSET =
|
|
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|[+-]\d{2}:\d{2})$/;
|
|
|
|
export const normalizeAiDateString = (input: string): string => {
|
|
if (ISO_DATETIME_WITH_OFFSET.test(input)) return input;
|
|
const parsed = parseISO(input);
|
|
return formatISO(parsed);
|
|
};
|