From 4b9867bd165967367d0345e843292d966f71df77 Mon Sep 17 00:00:00 2001 From: James Collins Date: Tue, 14 Mar 2023 18:44:29 +1000 Subject: [PATCH] fix incorrect parsing of some dates --- resources/js/helpers/datetime.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/js/helpers/datetime.ts b/resources/js/helpers/datetime.ts index 60ac1de..878cad8 100644 --- a/resources/js/helpers/datetime.ts +++ b/resources/js/helpers/datetime.ts @@ -167,7 +167,24 @@ export class SMDate { parsedHours = parseInt(match[1]); parsedMinutes = match[2] ? parseInt(match[2]) : 0; parsedSeconds = match[3] ? parseInt(match[3]) : 0; - if (match[4] && /pm/i.test(match[4])) { + + if ( + parsedHours < 0 || + parsedHours > 23 || + (match[4] && + (/(am|pm)/i.test(match[4]) == false || + parsedHours > 12)) || + parsedMinutes < 0 || + parsedMinutes > 59 || + parsedSeconds < 0 || + parsedSeconds > 59 + ) { + // not valid + this.date = null; + return this; + } + + if (match[4] && /pm/i.test(match[4]) && parsedHours < 12) { parsedHours += 12; } if (