1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.addToRange = addToRange;
|
4 | const index_js_1 = require("../lib/index.js");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function addToRange(date, range,
|
14 | /** @ignore */
|
15 | dateLib = index_js_1.dateLib) {
|
16 | const { from, to } = range || {};
|
17 | const { isSameDay, isAfter, isBefore } = dateLib;
|
18 | if (from && to) {
|
19 | if (isSameDay(to, date) && isSameDay(from, date)) {
|
20 | return { from: undefined, to: undefined };
|
21 | }
|
22 | if (isSameDay(to, date)) {
|
23 | return { from: to, to: undefined };
|
24 | }
|
25 | if (isSameDay(from, date)) {
|
26 | return { from: undefined, to: undefined };
|
27 | }
|
28 | if (isAfter(from, date)) {
|
29 | return { from: date, to };
|
30 | }
|
31 | return { from, to: date };
|
32 | }
|
33 | if (to) {
|
34 | if (isAfter(date, to)) {
|
35 | return { from: to, to: date };
|
36 | }
|
37 | return { from: date, to };
|
38 | }
|
39 | if (from) {
|
40 | if (isBefore(date, from)) {
|
41 | return { from: date, to: from };
|
42 | }
|
43 | if (isSameDay(date, from)) {
|
44 | return { from: undefined, to: undefined };
|
45 | }
|
46 | return { from, to: date };
|
47 | }
|
48 | return { from: date, to: undefined };
|
49 | }
|
50 |
|
\ | No newline at end of file |