1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.isDateInRange = void 0;
|
4 | exports.rangeIncludesDate = rangeIncludesDate;
|
5 | const index_js_1 = require("../lib/index.js");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function rangeIncludesDate(range, date,
|
13 | /** If `true`, the ends of the range are excluded. */
|
14 | excludeEnds = false,
|
15 | /** @ignore */
|
16 | dateLib = 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 |
|
38 |
|
39 |
|
40 | const isDateInRange = (range, date) => rangeIncludesDate(range, date, false, index_js_1.dateLib);
|
41 | exports.isDateInRange = isDateInRange;
|
42 |
|
\ | No newline at end of file |