From 6c5f1e0c18df880927072e57adacfb3b6baade4a Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 20 Feb 2025 10:14:56 +1100 Subject: [PATCH] fix: validate date object and ensure month and day are within valid ranges --- src/components/SingleDatePicker.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/SingleDatePicker.tsx b/src/components/SingleDatePicker.tsx index 6faa1a5..4b248af 100644 --- a/src/components/SingleDatePicker.tsx +++ b/src/components/SingleDatePicker.tsx @@ -91,6 +91,13 @@ export default ({ value, onSelect, localization, onClose, mainColor = '#000000', useEffect(() => { if (!value) return + if (!(value instanceof Date)) { + if (value.year < 100) value.year = Number(`20${value.year}`) + if (value.month < 0 || value.month > 11) + return console.warn('Invalid value: Month should be between 1 and 12.') + if (value.day < 1 || value.day > 31) + return console.warn('Invalid value: Day should be between 1 and 31.') + } const date = value instanceof Date ? value : new Date(value.year, value.month - 1, value.day) setSelectedDate(date) setCurrentMonth(date.getMonth())