diff --git a/src/components/DatePicker/DatePicker.jsx b/src/components/DatePicker/DatePicker.jsx index 179a44f80..9d4e5d1d7 100644 --- a/src/components/DatePicker/DatePicker.jsx +++ b/src/components/DatePicker/DatePicker.jsx @@ -145,12 +145,27 @@ export const DatePicker = ({ const to = toDate(now(day, timezoneName).endOf("day"), false); onChange({ from, to }, options, event); - } else { + } else if (DateUtils.isDayBefore(value.from, toDate(now(day, timezoneName)))) { + // this works if the user first clicked on the date that will go to "from", and the second click to "to" onChange( DateUtils.addDayToRange(toDate(now(day, timezoneName).endOf("day"), false), value), options, event, ); + } else if ( + DateUtils.isDayAfter(value.from, toDate(now(day, timezoneName))) || + DateUtils.isSameDay(value.from, toDate(now(day, timezoneName))) + ) { + // this works if the user first clicked on the date that will go to "to", and the second click to "from" + // also this works when the user has selected one date + onChange( + { + from: toDate(now(day, timezoneName).startOf("day")), + to: toDate(now(value.from).endOf("day"), false), + }, + options, + event, + ); } } else { onChange(toDate(now(day, timezoneName)), options, event);