diff --git a/src/lib/datepicker/Datepicker.svelte b/src/lib/datepicker/Datepicker.svelte index 503ea4400..c4d5edb7f 100644 --- a/src/lib/datepicker/Datepicker.svelte +++ b/src/lib/datepicker/Datepicker.svelte @@ -161,12 +161,17 @@ return date.toLocaleDateString(locale, dateFormat); } - function isSelected(day: Date): boolean { + function isSameDate(date1: Date | null, date2: Date | null): boolean { + if (!date1 || !date2) return false; + return date1.toDateString() === date2.toDateString(); + } + + $: isSelected = (day: Date): boolean => { if (range) { - return !!(rangeFrom && day.toDateString() === rangeFrom.toDateString()) || !!(rangeTo && day.toDateString() === rangeTo.toDateString()); + return isSameDate(day, rangeFrom) || isSameDate(day, rangeTo); } - return !!(value && day.toDateString() === value.toDateString()); - } + return isSameDate(day, value); + }; function isInRange(day: Date): boolean { if (!range || !rangeFrom || !rangeTo) return false;