From 0df0d8f42a2c52ad0eebd36b92ac3ca01538568b Mon Sep 17 00:00:00 2001 From: Rahul Barwal Date: Tue, 5 Nov 2024 11:54:23 +0530 Subject: [PATCH] chore: Enhance date validation logic in DatePickerWidget2 for better granularity checks (#37210) --- .../DatePickerWidget2/widget/derived.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/client/src/widgets/DatePickerWidget2/widget/derived.js b/app/client/src/widgets/DatePickerWidget2/widget/derived.js index cda0937f7e3..fd816fbc2bc 100644 --- a/app/client/src/widgets/DatePickerWidget2/widget/derived.js +++ b/app/client/src/widgets/DatePickerWidget2/widget/derived.js @@ -10,9 +10,31 @@ export default { let dateValid = true; if (!!props.minDate && !!props.maxDate) { - dateValid = !!selectedDate - ? selectedDate.isBetween(minDate, maxDate) - : !props.isRequired; + if (!selectedDate) { + dateValid = !props.isRequired; + } else { + let granularityToCheck = undefined; + let inclusivityMarkers = undefined; + + switch (props.timePrecision) { + case "None": + granularityToCheck = "day"; + inclusivityMarkers = "[]"; + break; + case "second": + case "minute": + case "millisecond": + granularityToCheck = props.timePrecision; + inclusivityMarkers = "[]"; + break; + } + dateValid = selectedDate.isBetween( + minDate, + maxDate, + granularityToCheck, + inclusivityMarkers, + ); + } } else if (!!props.minDate) { dateValid = !!selectedDate ? selectedDate.isAfter(minDate)