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);
};
