1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.dateMatchModifiers = dateMatchModifiers;
|
4 | const rangeIncludesDate_js_1 = require("./rangeIncludesDate.js");
|
5 | const typeguards_js_1 = require("./typeguards.js");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function dateMatchModifiers(date, matchers, dateLib) {
|
26 | const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
|
27 | const { isSameDay, differenceInCalendarDays, isAfter } = dateLib;
|
28 | return matchersArr.some((matcher) => {
|
29 | if (typeof matcher === "boolean") {
|
30 | return matcher;
|
31 | }
|
32 | if (dateLib.isDate(matcher)) {
|
33 | return isSameDay(date, matcher);
|
34 | }
|
35 | if ((0, typeguards_js_1.isDatesArray)(matcher, dateLib)) {
|
36 | return matcher.includes(date);
|
37 | }
|
38 | if ((0, typeguards_js_1.isDateRange)(matcher)) {
|
39 | return (0, rangeIncludesDate_js_1.rangeIncludesDate)(matcher, date, false, dateLib);
|
40 | }
|
41 | if ((0, typeguards_js_1.isDayOfWeekType)(matcher)) {
|
42 | if (!Array.isArray(matcher.dayOfWeek)) {
|
43 | return matcher.dayOfWeek === date.getDay();
|
44 | }
|
45 | return matcher.dayOfWeek.includes(date.getDay());
|
46 | }
|
47 | if ((0, typeguards_js_1.isDateInterval)(matcher)) {
|
48 | const diffBefore = differenceInCalendarDays(matcher.before, date);
|
49 | const diffAfter = differenceInCalendarDays(matcher.after, date);
|
50 | const isDayBefore = diffBefore > 0;
|
51 | const isDayAfter = diffAfter < 0;
|
52 | const isClosedInterval = isAfter(matcher.before, matcher.after);
|
53 | if (isClosedInterval) {
|
54 | return isDayAfter && isDayBefore;
|
55 | }
|
56 | else {
|
57 | return isDayBefore || isDayAfter;
|
58 | }
|
59 | }
|
60 | if ((0, typeguards_js_1.isDateAfterType)(matcher)) {
|
61 | return differenceInCalendarDays(date, matcher.after) > 0;
|
62 | }
|
63 | if ((0, typeguards_js_1.isDateBeforeType)(matcher)) {
|
64 | return differenceInCalendarDays(matcher.before, date) > 0;
|
65 | }
|
66 | if (typeof matcher === "function") {
|
67 | return matcher(date);
|
68 | }
|
69 | return false;
|
70 | });
|
71 | }
|
72 |
|
\ | No newline at end of file |