From 71ad30f396084a4eec58dc3ba07ce535f8bfb267 Mon Sep 17 00:00:00 2001 From: Goostaf Date: Tue, 30 Jan 2024 20:54:02 +0100 Subject: [PATCH] Allow same-day rules (#99) --- backend/src/services/rule.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/services/rule.service.ts b/backend/src/services/rule.service.ts index 15b9c12..0a00a30 100644 --- a/backend/src/services/rule.service.ts +++ b/backend/src/services/rule.service.ts @@ -186,6 +186,10 @@ export const checkRules = async (prisma: PrismaClient, event: Event) => { }; const validDate = (start: Date, end: Date): boolean => { + return start.getTime() > 0 && end.getTime() > 0 && start <= end; +}; + +const validDateTime = (start: Date, end: Date): boolean => { return start.getTime() > 0 && end.getTime() > 0 && start < end; }; @@ -213,7 +217,7 @@ export const createRule = async ( const start_time = new Date(rule.start_date + "T" + rule.start_time); const end_time = new Date(rule.start_date + "T" + rule.end_time); - if (!validDate(start_time, end_time)) { + if (!validDateTime(start_time, end_time)) { return { sv: "Ogiltig tid", en: "Invalid time",