1 | import { dateLib as defaultDateLib } from "../lib/index.js";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function rangeIncludesDate(range, date,
|
9 | /** If `true`, the ends of the range are excluded. */
|
10 | excludeEnds = false,
|
11 | /** @ignore */
|
12 | dateLib = 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 |
|
34 |
|
35 |
|
36 | export const isDateInRange = (range, date) => rangeIncludesDate(range, date, false, defaultDateLib);
|
37 |
|
\ | No newline at end of file |