Skip to content

Commit

Permalink
fix(datepicker): adds Optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
2nikhiltom committed Nov 12, 2024
1 parent 664408d commit b036f77
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default (config) => (fp) => {
if (inputTo === target && fp.selectedDates[1]) {
// Using getTime() enables the ability to more readily compare the date currently
// selected in the calendar and the date currently in the value of the input
const withoutTime = (date) => date.setHours(0, 0, 0, 0);
const withoutTime = (date) => date?.setHours(0, 0, 0, 0);
const selectedToDate = withoutTime(new Date(fp.selectedDates[1]));
const currentValueToDate = withoutTime(
parseDateWithFormat(inputTo.value)
Expand All @@ -104,7 +104,7 @@ export default (config) => (fp) => {
}
}

const isValidDate = (date) => date.toString() !== 'Invalid Date';
const isValidDate = (date) => date?.toString() !== 'Invalid Date';
// save end date in calendar inmediately after it's been written down
if (inputTo === target && fp.selectedDates.length === 1 && inputTo.value) {
if (isValidDate(parseDateWithFormat(inputTo.value))) {
Expand Down

0 comments on commit b036f77

Please sign in to comment.