From 101b2bbe0d1d441bec81c32389dc72249f8f3460 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 31 Oct 2023 10:19:30 -0700 Subject: [PATCH] edit-date: construction and validation (fix #671) Signed-off-by: Varun Patil --- src/components/modal/EditDate.vue | 44 ++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/components/modal/EditDate.vue b/src/components/modal/EditDate.vue index 9723d5d4..e5f96158 100644 --- a/src/components/modal/EditDate.vue +++ b/src/components/modal/EditDate.vue @@ -10,6 +10,8 @@ 5000) return null; + if (month < 0 || month > 11) return null; + + // Number of days in month + const daysInMonth = new Date(year, month + 1, 0).getDate(); + if (day < 1 || day > daysInMonth) return null; + + // Validate time + if (hour < 0 || hour > 23) return null; + if (minute < 0 || minute > 59) return null; + if (second < 0 || second > 59) second = 0; + + return new Date(Date.UTC(year, month, day, hour, minute, second)); }, }, });