UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.addToRange = addToRange;
4const index_js_1 = require("../lib/index.js");
5/**
6 * Add a day to an existing range.
7 *
8 * The returned range takes in account the `undefined` values and if the added
9 * day is already present in the range.
10 *
11 * @group Utilities
12 */
13function addToRange(date, range,
14/** @ignore */
15dateLib = 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//# sourceMappingURL=addToRange.js.map
\No newline at end of file