UNPKG

1.19 kBJavaScriptView Raw
1import { dateLib as defaultDateLib } from "../lib/index.js";
2/**
3 * Determines whether a given date is inside a specified date range.
4 *
5 * @since 9.0.0
6 * @group Utilities
7 */
8export function rangeIncludesDate(range, date,
9/** If `true`, the ends of the range are excluded. */
10excludeEnds = false,
11/** @ignore */
12dateLib = defaultDateLib) {
13 let { from, to } = range;
14 const { differenceInCalendarDays, isSameDay } = dateLib;
15 if (from && to) {
16 const isRangeInverted = differenceInCalendarDays(to, from) < 0;
17 if (isRangeInverted) {
18 [from, to] = [to, from];
19 }
20 const isInRange = differenceInCalendarDays(date, from) >= (excludeEnds ? 1 : 0) &&
21 differenceInCalendarDays(to, date) >= (excludeEnds ? 1 : 0);
22 return isInRange;
23 }
24 if (!excludeEnds && to) {
25 return isSameDay(to, date);
26 }
27 if (!excludeEnds && from) {
28 return isSameDay(from, date);
29 }
30 return false;
31}
32/**
33 * @private
34 * @deprecated Use {@link rangeIncludesDate} instead.
35 */
36export const isDateInRange = (range, date) => rangeIncludesDate(range, date, false, defaultDateLib);
37//# sourceMappingURL=rangeIncludesDate.js.map
\No newline at end of file