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

pull/5042/head^2
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
1 changed files with 14 additions and 0 deletions

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(),