fix LastDayInRange when a time is selected

This commit is contained in:
Bernt Christian Egeland 2023-01-23 19:58:40 +01:00
parent 6a98ec9665
commit dd609bfa21

View File

@ -102,8 +102,9 @@ const Calendar = ({ onChange, calendarRef, close, dateRange, children }) => {
...prev, ...prev,
selectedDay: todayTimestamp, selectedDay: todayTimestamp,
monthDetails: getMonthDetails(year, month), monthDetails: getMonthDetails(year, month),
timeRange: { ...dateRange },
})); }));
}, [year, month, getMonthDetails]); }, [year, month, getMonthDetails, dateRange]);
useEffect(() => { useEffect(() => {
// add refs for keyboard navigation // add refs for keyboard navigation
@ -136,10 +137,14 @@ const Calendar = ({ onChange, calendarRef, close, dateRange, children }) => {
const isLastDayInRange = useCallback( const isLastDayInRange = useCallback(
(day) => { (day) => {
return ( // if the hour is not above 0, we will use 24 hour.
new Date(state.timeRange.before).setHours(24) === new Date(day.timestamp).setHours(24) || const beforeHour = new Date(state.timeRange.before).getHours() || 24;
state.timeRange.before === new Date(day.timestamp).setHours(24)
); /**
* When user selects a day in the calendar, the before will be 00:00.
* When user selects a time in timepicker, the day.timestamp hour must be changed to match the selected end () hour.
*/
return state.timeRange.before === new Date(day.timestamp).setHours(beforeHour);
}, },
[state.timeRange.before] [state.timeRange.before]
); );