Skip to content

Commit

Permalink
X2-10221 | fixed datepicker for specific case (#336)
Browse files Browse the repository at this point in the history
* X2-10221 | fixed datepicker for case when user first clicked on the date that will go to 'to'and then to 'from'

* fexed lint issue

* added comment

* added missing argument

* added condition for same date
  • Loading branch information
VitalyDevico authored Aug 2, 2024
1 parent e1c740e commit b7d4d06
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/DatePicker/DatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b7d4d06

Please sign in to comment.