Adds a iso8601 helper function to parse a ISO Date String into a Date (#5039)

This commit is contained in:
Alex van Andel 2022-10-17 10:07:49 +01:00 committed by GitHub
parent 0fc1449dd9
commit d8489a662e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,6 +58,20 @@ export const recurringEventType = z
})
.nullable();
// dayjs iso parsing is very buggy - cant use :( - turns ISO string into Date object
export const iso8601 = z.string().transform((val, ctx) => {
const time = Date.parse(val);
if (!time) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Invalid ISO Date",
});
}
const d = new Date();
d.setTime(time);
return d;
});
export const bookingLimitsType = z
.object({
PER_DAY: z.number().optional(),