UNPKG

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