Utilities
The package exports two utilities that are useful when you want booking-aware logic outside the UI components.
getProtectedTime
import {
getProtectedTime,
type CalendarReserved,
} from "@demark-pro/react-booking-calendar";
const reserved = [
{
startDate: new Date(2030, 4, 12, 14, 0),
endDate: new Date(2030, 4, 14, 10, 0),
},
];
const result = getProtectedTime(new Date(2030, 4, 12), reserved);
Returns:
type GetProtectedTimeReturn = {
startDate: Date;
endDate: Date;
};
Use it when you want to snap a selected day to the protected reservation boundaries.
getProtectedInterval
import {
getProtectedInterval,
type CalendarDayState,
} from "@demark-pro/react-booking-calendar";
const result = getProtectedInterval(date, state, {
selected,
reserved,
disabled,
protection,
range,
isStart,
options,
getClassNames,
});
Returns:
type GetProtectedIntervalReturn = {
interval: CalendarSelected[] | null;
overbookType: OverbookTypes | null;
};
Use it when you need to mirror the calendar selection rules in a higher-level booking flow, analytics layer, or custom interaction surface.
Which one to use
- Use
getProtectedTimewhen you already know the day and only need protected check-in or check-out boundaries. - Use
getProtectedIntervalwhen you want the same accept-or-reject decision that the calendar uses while handling clicks.