@geotab/zenith 1.15.4 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/calendar/calendar.d.ts +4 -2
- package/dist/calendar/calendar.js +73 -76
- package/dist/calendar/calendarUtils.d.ts +5 -2
- package/dist/calendar/calendarUtils.js +8 -34
- package/dist/calendar/dateUtils.d.ts +6 -1
- package/dist/calendar/dateUtils.js +25 -94
- package/dist/commonStyles/pillStyles/pillContent.less +2 -2
- package/dist/dateInput/dateInput.js +7 -5
- package/dist/dateInputInner/dateInputInner.js +396 -97
- package/dist/dateInputInner/dateInputInnerControlBlock.d.ts +6 -1
- package/dist/dateInputInner/dateInputInnerControlBlock.js +17 -6
- package/dist/dateInputInner/dateInputInnerReducer.d.ts +109 -0
- package/dist/dateInputInner/dateInputInnerReducer.js +134 -0
- package/dist/dateRange/dateRange.d.ts +1 -0
- package/dist/dateRange/dateRange.js +26 -24
- package/dist/dateRange/dateRangeUtils.d.ts +1 -0
- package/dist/dateRangeInner/dateRangeInner.d.ts +2 -2
- package/dist/dateRangeInner/dateRangeInner.js +15 -17
- package/dist/dropdown/dropdown.js +6 -2
- package/dist/filtersBar/components/filtersBarDropdown/filtersBarDropdown.d.ts +1 -1
- package/dist/filtersBar/components/filtersBarDropdown/filtersBarDropdown.js +1 -1
- package/dist/filtersBar/components/filtersBarPeriodPicker/filtersBarPeriodPicker.js +10 -10
- package/dist/filtersBar/components/filtersBarPeriodPicker/getRangeOption.d.ts +8 -2
- package/dist/filtersBar/components/filtersBarPeriodPicker/getRangeOption.js +25 -11
- package/dist/filtersBar/components/filtersBarPeriodPicker/normalizeDates.js +10 -8
- package/dist/header/components/collapsedItemsControl/collapsedItemsControl.js +1 -1
- package/dist/header/header.js +2 -1
- package/dist/header/headerContext.d.ts +9 -0
- package/dist/header/headerContext.js +8 -0
- package/dist/header/headerHelpers.js +6 -3
- package/dist/header/headerMenu.d.ts +2 -0
- package/dist/header/headerMenu.js +2 -2
- package/dist/index.css +110 -23
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -18
- package/dist/menu/components/menuItem.js +5 -2
- package/dist/parallelSelection/parallelSelection.d.ts +2 -0
- package/dist/parallelSelection/parallelSelection.js +2 -2
- package/dist/timePicker/timePicker.d.ts +1 -0
- package/dist/timePicker/timePicker.js +4 -4
- package/dist/utils/dateInputUtils/useTodayButton.d.ts +5 -0
- package/dist/utils/dateInputUtils/useTodayButton.js +16 -0
- package/dist/utils/localization/translations/cs-json.d.ts +1 -0
- package/dist/utils/localization/translations/cs-json.js +2 -1
- package/dist/utils/localization/translations/de-json.d.ts +1 -0
- package/dist/utils/localization/translations/de-json.js +2 -1
- package/dist/utils/localization/translations/en-json.d.ts +16 -0
- package/dist/utils/localization/translations/en-json.js +17 -1
- package/dist/utils/localization/translations/es-json.d.ts +1 -0
- package/dist/utils/localization/translations/es-json.js +2 -1
- package/dist/utils/localization/translations/fr-FR-json.d.ts +1 -0
- package/dist/utils/localization/translations/fr-FR-json.js +2 -1
- package/dist/utils/localization/translations/fr-json.d.ts +1 -0
- package/dist/utils/localization/translations/fr-json.js +2 -1
- package/dist/utils/localization/translations/id-json.d.ts +1 -0
- package/dist/utils/localization/translations/id-json.js +2 -1
- package/dist/utils/localization/translations/it-json.d.ts +1 -0
- package/dist/utils/localization/translations/it-json.js +2 -1
- package/dist/utils/localization/translations/ja-json.d.ts +1 -0
- package/dist/utils/localization/translations/ja-json.js +2 -1
- package/dist/utils/localization/translations/ms-json.d.ts +1 -0
- package/dist/utils/localization/translations/ms-json.js +2 -1
- package/dist/utils/localization/translations/nl-json.d.ts +1 -0
- package/dist/utils/localization/translations/nl-json.js +2 -1
- package/dist/utils/localization/translations/pl-json.d.ts +1 -0
- package/dist/utils/localization/translations/pl-json.js +2 -1
- package/dist/utils/localization/translations/pt-BR-json.d.ts +1 -0
- package/dist/utils/localization/translations/pt-BR-json.js +2 -1
- package/dist/utils/localization/translations/sv-json.d.ts +1 -0
- package/dist/utils/localization/translations/sv-json.js +2 -1
- package/dist/utils/localization/translations/th-json.d.ts +1 -0
- package/dist/utils/localization/translations/th-json.js +2 -1
- package/dist/utils/localization/translations/tr-json.d.ts +1 -0
- package/dist/utils/localization/translations/tr-json.js +2 -1
- package/dist/utils/localization/translations/zh-Hans-json.d.ts +1 -0
- package/dist/utils/localization/translations/zh-Hans-json.js +2 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -40,6 +40,14 @@ Zenith library provides components defined in Zenith Design System. It includes
|
|
|
40
40
|
|
|
41
41
|
## Change log
|
|
42
42
|
|
|
43
|
+
## 1.16.1
|
|
44
|
+
|
|
45
|
+
* Improve dateRange component
|
|
46
|
+
* Fix unreliable test
|
|
47
|
+
* Audit: table, pills, text-secondary for placeholder color, specs for the banner component
|
|
48
|
+
* Improve Header: Make Menu.Item to be bottom-right aligned in Header
|
|
49
|
+
* Improve FiltersBar: Show selected values as pills in the sidePanel dropdown when getSelectedItem is passed
|
|
50
|
+
|
|
43
51
|
## 1.15.4
|
|
44
52
|
|
|
45
53
|
* Fix unreliable tests
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import "./calendar.less";
|
|
3
3
|
import { IZenComponentProps } from "../commonHelpers/zenComponent";
|
|
4
|
+
export declare const monthLabelsArray: string[];
|
|
4
5
|
export interface ICalendarRange {
|
|
5
6
|
from?: string;
|
|
6
7
|
to?: string;
|
|
@@ -8,7 +9,7 @@ export interface ICalendarRange {
|
|
|
8
9
|
export interface ICalendar extends IZenComponentProps {
|
|
9
10
|
id: string;
|
|
10
11
|
value: ICalendarRange;
|
|
11
|
-
onChange: (value: ICalendarRange) => void;
|
|
12
|
+
onChange: (value: ICalendarRange, active?: "start" | "end") => void;
|
|
12
13
|
/**
|
|
13
14
|
* @deprecated
|
|
14
15
|
* @param translate - will be removed in the next major release
|
|
@@ -22,7 +23,8 @@ export interface ICalendar extends IZenComponentProps {
|
|
|
22
23
|
startDayOfWeek?: number;
|
|
23
24
|
yearRange?: number;
|
|
24
25
|
isMobileView?: boolean;
|
|
25
|
-
|
|
26
|
+
onTodayButtonClick?: (e: any) => void;
|
|
27
|
+
getCurrentActiveField?: () => "start" | "end";
|
|
26
28
|
}
|
|
27
29
|
export declare const Calendar: React.FC<ICalendar>;
|
|
28
30
|
export declare const TRANSLATIONS: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TRANSLATIONS = exports.Calendar = void 0;
|
|
3
|
+
exports.TRANSLATIONS = exports.Calendar = exports.monthLabelsArray = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const dateUtils_1 = require("./dateUtils");
|
|
@@ -13,9 +13,12 @@ const useLanguage_1 = require("../utils/localization/useLanguage");
|
|
|
13
13
|
const useDriveClassName_1 = require("../utils/theme/useDriveClassName");
|
|
14
14
|
const textIconButton_1 = require("../textIconButton/textIconButton");
|
|
15
15
|
const textIconButton_2 = require("../textIconButton/textIconButton");
|
|
16
|
+
const button_1 = require("../button/button");
|
|
17
|
+
const buttonType_1 = require("../button/buttonType");
|
|
16
18
|
const DEFAULT_START_DAY_OF_WEEK = 0;
|
|
17
19
|
const DEFAULT_YEAR_RANGE = 20;
|
|
18
|
-
|
|
20
|
+
exports.monthLabelsArray = ["Jan", "Feb", "Mar", "Apr", "Ma", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
21
|
+
const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePastDates = false, disableDatesAfter, disableDatesBefore, dateRangeMode = false, startDayOfWeek, yearRange, isMobileView, getCurrentActiveField, onTodayButtonClick }) => {
|
|
19
22
|
const { translate } = (0, useLanguage_1.useLanguage)();
|
|
20
23
|
const fromDate = (0, react_1.useMemo)(() => value.from ? (0, dateUtils_1.toDayStart)(value.from) : undefined, [value.from]);
|
|
21
24
|
const toDate = (0, react_1.useMemo)(() => value.to ? (0, dateUtils_1.toDayStart)(value.to) : undefined, [value.to]);
|
|
@@ -36,10 +39,16 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
36
39
|
}
|
|
37
40
|
setViewDate(dateLike.toISOString());
|
|
38
41
|
}, [setViewDate]);
|
|
39
|
-
const handleFocusDateChange = (0, react_1.useCallback)((date) => {
|
|
42
|
+
const handleFocusDateChange = (0, react_1.useCallback)((focusing = false) => (date) => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (date && focusing) {
|
|
45
|
+
const dateLike = new Date(date);
|
|
46
|
+
const button = (_a = parentRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-id="${id}-day-${dateLike.getDate()}-${dateLike.getMonth()}-${dateLike.getFullYear()}"]`);
|
|
47
|
+
button === null || button === void 0 ? void 0 : button.focus();
|
|
48
|
+
}
|
|
40
49
|
changeView(date);
|
|
41
50
|
setFocusDate(date);
|
|
42
|
-
}, [changeView, setFocusDate]);
|
|
51
|
+
}, [changeView, setFocusDate, id]);
|
|
43
52
|
const dayLabels = (0, react_1.useMemo)(() => ({
|
|
44
53
|
0: translate("ShortSunday"),
|
|
45
54
|
1: translate("ShortMonday"),
|
|
@@ -54,18 +63,18 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
54
63
|
return dayLabels[dayOfWeek];
|
|
55
64
|
}, [dayLabels]);
|
|
56
65
|
const monthLabels = (0, react_1.useMemo)(() => ({
|
|
57
|
-
0: translate(
|
|
58
|
-
1: translate(
|
|
59
|
-
2: translate(
|
|
60
|
-
3: translate(
|
|
61
|
-
4: translate(
|
|
62
|
-
5: translate(
|
|
63
|
-
6: translate(
|
|
64
|
-
7: translate(
|
|
65
|
-
8: translate(
|
|
66
|
-
9: translate(
|
|
67
|
-
10: translate(
|
|
68
|
-
11: translate(
|
|
66
|
+
0: translate(exports.monthLabelsArray[0]),
|
|
67
|
+
1: translate(exports.monthLabelsArray[1]),
|
|
68
|
+
2: translate(exports.monthLabelsArray[2]),
|
|
69
|
+
3: translate(exports.monthLabelsArray[3]),
|
|
70
|
+
4: translate(exports.monthLabelsArray[4]),
|
|
71
|
+
5: translate(exports.monthLabelsArray[5]),
|
|
72
|
+
6: translate(exports.monthLabelsArray[6]),
|
|
73
|
+
7: translate(exports.monthLabelsArray[7]),
|
|
74
|
+
8: translate(exports.monthLabelsArray[8]),
|
|
75
|
+
9: translate(exports.monthLabelsArray[9]),
|
|
76
|
+
10: translate(exports.monthLabelsArray[10]),
|
|
77
|
+
11: translate(exports.monthLabelsArray[11])
|
|
69
78
|
}), [translate]);
|
|
70
79
|
const getMonthYear = (0, react_1.useCallback)((date) => {
|
|
71
80
|
const month = new Date(date).getMonth();
|
|
@@ -80,13 +89,12 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
80
89
|
const selectionHandler = (0, react_1.useCallback)(
|
|
81
90
|
// eslint-disable-next-line complexity
|
|
82
91
|
(selectedDate, isOtherMonth) => {
|
|
83
|
-
var _a;
|
|
84
92
|
setHoverDate(undefined);
|
|
85
93
|
if (isOtherMonth) {
|
|
86
|
-
handleFocusDateChange(selectedDate);
|
|
94
|
+
handleFocusDateChange()(selectedDate);
|
|
87
95
|
}
|
|
88
96
|
// single date mode
|
|
89
|
-
if (!dateRangeMode) {
|
|
97
|
+
if (!dateRangeMode || !getCurrentActiveField) {
|
|
90
98
|
if (fromDate && fromDate === selectedDate) {
|
|
91
99
|
onChange({ from: undefined, to: undefined });
|
|
92
100
|
}
|
|
@@ -95,47 +103,34 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
95
103
|
}
|
|
96
104
|
return;
|
|
97
105
|
}
|
|
106
|
+
const currentActiveField = getCurrentActiveField();
|
|
98
107
|
// no selection yet
|
|
99
108
|
if (!fromDate && !toDate) {
|
|
100
|
-
onChange({ from: selectedDate, to: undefined });
|
|
109
|
+
onChange({ from: currentActiveField === "start" ? selectedDate : undefined, to: currentActiveField === "end" ? selectedDate : undefined }, currentActiveField);
|
|
101
110
|
return;
|
|
102
111
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
onChange({ from: toDate, to: undefined });
|
|
112
|
+
if (currentActiveField === "start" && toDate && selectedDate > toDate) {
|
|
113
|
+
onChange({ from: selectedDate, to: undefined }, "start");
|
|
106
114
|
return;
|
|
107
115
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
onChange({ from: fromDate, to: undefined });
|
|
116
|
+
if (currentActiveField === "end" && fromDate && selectedDate < fromDate) {
|
|
117
|
+
onChange({ from: undefined, to: selectedDate }, "end");
|
|
111
118
|
return;
|
|
112
119
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const newFrom = selectedDate <= fromDate ? selectedDate : fromDate;
|
|
116
|
-
const newTo = selectedDate <= fromDate ? fromDate : selectedDate;
|
|
117
|
-
const isWrongPeriod = (0, dateUtils_1.isDifferentPeriod)(new Date(newFrom), new Date(newTo), disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
118
|
-
if (isWrongPeriod) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (selectedDate < fromDate) {
|
|
122
|
-
onChange({ from: selectedDate, to: fromDate });
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
onChange({ from: fromDate, to: selectedDate });
|
|
120
|
+
if (fromDate && selectedDate === fromDate && currentActiveField === "end") {
|
|
121
|
+
onChange({ from: selectedDate, to: selectedDate }, "end");
|
|
126
122
|
return;
|
|
127
123
|
}
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
const startDateId = `${id}-start`;
|
|
131
|
-
const endDateId = `${id}-end`;
|
|
132
|
-
const isWrongPeriodFn = (start, end) => (0, dateUtils_1.isDifferentPeriod)(start, end, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
133
|
-
const newRangeOptions = (0, calendarUtils_1.getCalendarRange)(selectedDate, isWrongPeriodFn, fromDate, toDate, previousActiveElementId === startDateId, previousActiveElementId === endDateId);
|
|
134
|
-
onChange(newRangeOptions);
|
|
124
|
+
if (toDate && selectedDate === toDate && currentActiveField === "start") {
|
|
125
|
+
onChange({ from: selectedDate, to: selectedDate }, "start");
|
|
135
126
|
return;
|
|
136
127
|
}
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
const isWrongPeriodFn = (start, end) => (0, dateUtils_1.isDifferentPeriod)(start, end, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter);
|
|
129
|
+
const newRangeOptions = (0, calendarUtils_1.getCalendarRange)(selectedDate, currentActiveField, isWrongPeriodFn, fromDate, toDate);
|
|
130
|
+
onChange(newRangeOptions, currentActiveField);
|
|
131
|
+
return;
|
|
132
|
+
}, [dateRangeMode, getCurrentActiveField, fromDate, toDate, onChange, handleFocusDateChange,
|
|
133
|
+
disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter]);
|
|
139
134
|
const handleDateKeyDown = (0, react_1.useCallback)((e, isDisabled, date, isOtherMonth) => {
|
|
140
135
|
if (e.code === "Enter" || e.code === "Space") {
|
|
141
136
|
e.preventDefault();
|
|
@@ -143,43 +138,43 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
143
138
|
return;
|
|
144
139
|
}
|
|
145
140
|
if (e.code === "ArrowLeft") {
|
|
146
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), -1).toISOString(), handleFocusDateChange);
|
|
141
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), -1).toISOString(), handleFocusDateChange(true));
|
|
147
142
|
return;
|
|
148
143
|
}
|
|
149
144
|
if (e.code === "ArrowRight") {
|
|
150
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), 1).toISOString(), handleFocusDateChange);
|
|
145
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), 1).toISOString(), handleFocusDateChange(true));
|
|
151
146
|
return;
|
|
152
147
|
}
|
|
153
148
|
if (e.code === "ArrowUp") {
|
|
154
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), -7).toISOString(), handleFocusDateChange);
|
|
149
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), -7).toISOString(), handleFocusDateChange(true));
|
|
155
150
|
return;
|
|
156
151
|
}
|
|
157
152
|
if (e.code === "ArrowDown") {
|
|
158
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), 7).toISOString(), handleFocusDateChange);
|
|
153
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.addDays)(new Date(date), 7).toISOString(), handleFocusDateChange(true));
|
|
159
154
|
return;
|
|
160
155
|
}
|
|
161
156
|
if (e.code === "Home") {
|
|
162
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getStartOfWeek)(date), handleFocusDateChange);
|
|
157
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getStartOfWeek)(date), handleFocusDateChange(true));
|
|
163
158
|
return;
|
|
164
159
|
}
|
|
165
160
|
if (e.code === "End") {
|
|
166
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getEndOfWeek)(date), handleFocusDateChange);
|
|
161
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getEndOfWeek)(date), handleFocusDateChange(true));
|
|
167
162
|
return;
|
|
168
163
|
}
|
|
169
164
|
if (e.code === "PageUp" && e.shiftKey) {
|
|
170
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, -12), handleFocusDateChange);
|
|
165
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, -12), handleFocusDateChange(true));
|
|
171
166
|
return;
|
|
172
167
|
}
|
|
173
168
|
if (e.code === "PageDown" && e.shiftKey) {
|
|
174
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, 12), handleFocusDateChange);
|
|
169
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, 12), handleFocusDateChange(true));
|
|
175
170
|
return;
|
|
176
171
|
}
|
|
177
172
|
if (e.code === "PageUp") {
|
|
178
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, -1), handleFocusDateChange);
|
|
173
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, -1), handleFocusDateChange(true));
|
|
179
174
|
return;
|
|
180
175
|
}
|
|
181
176
|
if (e.code === "PageDown") {
|
|
182
|
-
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, 1), handleFocusDateChange);
|
|
177
|
+
(0, calendarUtils_1.setFocusTo)(e, (0, dateUtils_1.getSameDateOrTheLastForMonth)(date, 1), handleFocusDateChange(true));
|
|
183
178
|
return;
|
|
184
179
|
}
|
|
185
180
|
}, [selectionHandler, handleFocusDateChange]);
|
|
@@ -194,23 +189,10 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
194
189
|
setFocusDate(undefined);
|
|
195
190
|
}, [selectionHandler]);
|
|
196
191
|
(0, react_1.useEffect)(() => {
|
|
197
|
-
|
|
198
|
-
// changing focused element only if focus is already in calendar
|
|
199
|
-
if ((((_a = focusRef.current) === null || _a === void 0 ? void 0 : _a.className.baseVal) || ((_b = focusRef.current) === null || _b === void 0 ? void 0 : _b.className) || "").indexOf("zen-calendar") === -1) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (!focusDate) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
const dateLike = new Date(focusDate);
|
|
206
|
-
const button = (_c = parentRef.current) === null || _c === void 0 ? void 0 : _c.querySelector(`[data-id="${id}-day-${dateLike.getDate()}-${dateLike.getMonth()}-${dateLike.getFullYear()}"]`);
|
|
207
|
-
button === null || button === void 0 ? void 0 : button.focus();
|
|
208
|
-
}, [id, viewDate, parentRef, focusDate]);
|
|
209
|
-
(0, react_1.useEffect)(() => {
|
|
210
|
-
value.to && handleFocusDateChange(value.to);
|
|
192
|
+
value.to && handleFocusDateChange()(value.to);
|
|
211
193
|
}, [value.to, handleFocusDateChange]);
|
|
212
194
|
(0, react_1.useEffect)(() => {
|
|
213
|
-
value.from && handleFocusDateChange(value.from);
|
|
195
|
+
value.from && handleFocusDateChange()(value.from);
|
|
214
196
|
}, [value.from, handleFocusDateChange]);
|
|
215
197
|
const getBeforeDecorator = (0, react_1.useCallback)((date, isFirstDayOfMonth, isFirstDayOfWeek) => {
|
|
216
198
|
if (!dateRangeMode) {
|
|
@@ -242,12 +224,21 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
242
224
|
}
|
|
243
225
|
return null;
|
|
244
226
|
}, [dateRangeMode, hoverDate, focusDate, fromDate, toDate]);
|
|
227
|
+
const handleTodayButtonClick = (0, react_1.useCallback)((e) => {
|
|
228
|
+
if (!onTodayButtonClick) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
setViewDate(new Date().toISOString());
|
|
232
|
+
onTodayButtonClick(e);
|
|
233
|
+
}, [onTodayButtonClick]);
|
|
245
234
|
const memoizedVisibleFocus = (0, react_1.useMemo)(() => focusDate ? dates.some(arr => arr.some(el => el === focusDate)) : true, [dates, focusDate]);
|
|
246
|
-
|
|
235
|
+
const currentActiveField = getCurrentActiveField ? getCurrentActiveField() : undefined;
|
|
236
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: parentRef, onBlur: () => setFocusDate(fromDate || viewDate), className: (0, classNames_1.classNames)(["zen-calendar", driveClassName || ""]), children: [(0, jsx_runtime_1.jsxs)("div", { className: "zen-calendar__header", children: [isMobileView ? null : (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { className: "zen-calendar__btn", type: "tertiary-black", icon: iconChevronLeftSmall_1.IconChevronLeftSmall, title: translate("Previous month"), onClick: () => changeView((0, dateUtils_1.addMonth)(viewDate, -1)), iconPosition: textIconButton_2.ButtonIconPosition.Start }), (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-calendar__year", onTodayButtonClick ? "zen-calendar__year--limited" : ""]), children: [(0, jsx_runtime_1.jsx)("div", { className: (0, classNames_1.classNames)(["zen-calendar__year-name", onTodayButtonClick ? "zen-calendar__year-name--left" : "", "zen-ellipsis"]), "aria-live": "polite", children: getMonthYear(viewDate) }), (0, jsx_runtime_1.jsx)(parallelSelection_1.ParallelSelectionTrigger, { className: "zen-calendar__year-trigger zen-calendar__btn", title: translate("Select year"), ref: parallelSelectionTriggerRef }), (0, jsx_runtime_1.jsx)(parallelSelection_1.ParallelSelection, { selected: new Date(viewDate).getFullYear().toString(), items: years, triggerRef: parallelSelectionTriggerRef, title: translate("Select year"), onSelect: year => changeView((0, dateUtils_1.setYear)(viewDate, year)), isMobileView: isMobileView, alignment: onTodayButtonClick ? "bottom" : "bottom-right" })] }), onTodayButtonClick ? (0, jsx_runtime_1.jsx)(button_1.Button, { type: buttonType_1.ButtonType.Tertiary, className: "zen-calendar__today-button", disabled: false, onClick: handleTodayButtonClick, children: translate("Today") }) : null, isMobileView ? (0, jsx_runtime_1.jsxs)("div", { className: "zen-calendar__months", children: [(0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { className: "zen-calendar__btn", type: "tertiary-black", icon: iconChevronLeftSmall_1.IconChevronLeftSmall, title: translate("Previous month"), onClick: () => changeView((0, dateUtils_1.addMonth)(viewDate, -1)), iconPosition: textIconButton_2.ButtonIconPosition.Start }), (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { className: "zen-calendar__btn", type: "tertiary-black", icon: iconChevronRightSmall_1.IconChevronRightSmall, title: translate("Next month"), onClick: () => changeView((0, dateUtils_1.addMonth)(viewDate, 1)), iconPosition: textIconButton_2.ButtonIconPosition.Start })] }) : null, isMobileView ? null : (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { className: "zen-calendar__btn", type: "tertiary-black", icon: iconChevronRightSmall_1.IconChevronRightSmall, title: translate("Next month"), onClick: () => changeView((0, dateUtils_1.addMonth)(viewDate, 1)), iconPosition: textIconButton_2.ButtonIconPosition.Start })] }), (0, jsx_runtime_1.jsxs)("table", { className: "zen-calendar__table", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsx)("tr", { className: "zen-calendar__columns", children: dates[0].map(date => (0, jsx_runtime_1.jsx)("th", { className: "zen-calendar__column", children: getDayOfWeek(date) }, `cal-h-${date}`)) }) }), (0, jsx_runtime_1.jsx)("tbody", { className: (0, classNames_1.classNames)(["zen-calendar__body", isMobileView ? "zen-calendar__body--mobile-view" : ""]), children: dates.map((week, weekIndex) => (0, jsx_runtime_1.jsx)("tr", { className: "zen-calendar__row", children: week.map((date, index) => {
|
|
247
237
|
const isOtherMonth = date < monthStart || date > monthEnd;
|
|
248
238
|
const isDisabled = isDisabledDay(date);
|
|
249
239
|
const dateLike = new Date(date);
|
|
250
240
|
const isActive = date === fromDate || date === toDate;
|
|
241
|
+
const isReadyToChange = date === fromDate && currentActiveField === "start" || date === toDate && currentActiveField === "end";
|
|
251
242
|
const isFocusable = memoizedVisibleFocus ? date === (fromDate || viewDate) : date.split("T")[0] === viewDate.split("T")[0];
|
|
252
243
|
const isFirstDayOfWeek = index === 0;
|
|
253
244
|
const isLastDayOfWeek = index === 6;
|
|
@@ -256,8 +247,14 @@ const Calendar = ({ id, value, onChange, disableFutureDates = false, disablePast
|
|
|
256
247
|
const isInRange = dateRangeMode && !isFirstDayOfWeek && !isLastDayOfWeek && (0, calendarUtils_1.isDateInRange)(date, hoverDate || focusDate, fromDate, toDate);
|
|
257
248
|
return (0, jsx_runtime_1.jsx)("td", { className: "zen-calendar__cell", children: (0, jsx_runtime_1.jsxs)("button", { className: (0, classNames_1.classNames)([
|
|
258
249
|
"zen-calendar__day-wrapper",
|
|
259
|
-
isActive ? "zen-calendar__day-wrapper--active" : ""
|
|
260
|
-
|
|
250
|
+
isActive ? "zen-calendar__day-wrapper--active" : "",
|
|
251
|
+
isReadyToChange ? "zen-calendar__day-wrapper--ready-to-change" : ""
|
|
252
|
+
]), onPointerDown: evt => {
|
|
253
|
+
evt.preventDefault();
|
|
254
|
+
!isDisabled && evt.button !== 2 && onPointerDown(date, isOtherMonth);
|
|
255
|
+
}, onPointerEnter: () => { !isDisabled && setHoverDate(date); }, onPointerLeave: () => { setHoverDate(undefined); }, tabIndex: isFocusable ? 0 : -1, type: "button", "data-id": `${id}-day-${dateLike.getDate()}-${dateLike.getMonth()}-${dateLike.getFullYear()}`, "aria-label": (0, calendarUtils_1.getButtonLabel)(translate, date, dateRangeMode, fromDate, toDate), onKeyDown: evt => handleDateKeyDown(evt, isDisabled, date, isOtherMonth), onFocus: () => {
|
|
256
|
+
!isDisabled && !isOtherMonth && handleFocusDateChange(true)(date);
|
|
257
|
+
}, disabled: isDisabled, children: [getBeforeDecorator(date, isFirstDayOfMonth, isFirstDayOfWeek), (0, jsx_runtime_1.jsx)("div", { className: (0, classNames_1.classNames)([
|
|
261
258
|
"zen-calendar__day",
|
|
262
259
|
isInRange ? "zen-calendar__day--in-range" : "",
|
|
263
260
|
isOtherMonth ? "zen-calendar__day--other-month" : "",
|
|
@@ -4,7 +4,10 @@ export declare const isRightBorderVisible: (date: string, hoverDate: string | un
|
|
|
4
4
|
export declare const isDateInRange: (date: string, hoverDate: string | undefined, startDate?: string, endDate?: string) => boolean;
|
|
5
5
|
export declare const getButtonLabel: (translate: (key: string) => string, date: string, isRangeMode: boolean, startDate?: string, endDate?: string) => string;
|
|
6
6
|
export declare const setFocusTo: (e: KeyboardEvent, date: string, selectionHandler: (d: string) => void) => void;
|
|
7
|
-
export declare const getCalendarRange: (selectedDate: string, isWrongPeriodFn: (dateStart?: Date, dateEnd?: Date) => boolean, dateFrom?: string, dateTo?: string
|
|
8
|
-
from: string
|
|
7
|
+
export declare const getCalendarRange: (selectedDate: string, currentActiveField: "start" | "end", isWrongPeriodFn: (dateStart?: Date, dateEnd?: Date) => boolean, dateFrom?: string, dateTo?: string) => {
|
|
8
|
+
from: string;
|
|
9
9
|
to: string | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
from: string | undefined;
|
|
12
|
+
to: string;
|
|
10
13
|
};
|
|
@@ -88,11 +88,11 @@ const setFocusTo = (e, date, selectionHandler) => {
|
|
|
88
88
|
};
|
|
89
89
|
exports.setFocusTo = setFocusTo;
|
|
90
90
|
// eslint-disable-next-line complexity
|
|
91
|
-
const getCalendarRange = (selectedDate, isWrongPeriodFn, dateFrom, dateTo
|
|
91
|
+
const getCalendarRange = (selectedDate, currentActiveField, isWrongPeriodFn, dateFrom, dateTo) => {
|
|
92
92
|
const selectedDateObj = new Date(selectedDate);
|
|
93
93
|
const dateFromObj = dateFrom && (0, dateUtils_1.isValidDate)(dateFrom) ? new Date(dateFrom) : undefined;
|
|
94
94
|
const dateToObj = dateTo && (0, dateUtils_1.isValidDate)(dateTo) ? new Date(dateTo) : undefined;
|
|
95
|
-
if (
|
|
95
|
+
if (currentActiveField === "start") {
|
|
96
96
|
// Cursor on Start Date
|
|
97
97
|
if (dateToObj && selectedDateObj.getTime() < dateToObj.getTime()) {
|
|
98
98
|
const isWrongPeriod = isWrongPeriodFn(selectedDateObj, dateToObj);
|
|
@@ -101,38 +101,12 @@ const getCalendarRange = (selectedDate, isWrongPeriodFn, dateFrom, dateTo, isPre
|
|
|
101
101
|
// Overlapping dates: selectedDate later than dateTo
|
|
102
102
|
return { from: selectedDate, to: undefined };
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return isWrongPeriod ? { from: undefined, to: selectedDate } : { from: dateFrom, to: selectedDate };
|
|
109
|
-
}
|
|
110
|
-
// Overlapping dates: selectedDate earlier than dateFrom
|
|
111
|
-
return { from: undefined, to: selectedDate };
|
|
112
|
-
}
|
|
113
|
-
// Cursor not on either field
|
|
114
|
-
if (!dateFromObj && (!dateToObj || selectedDateObj.getTime() > dateToObj.getTime())) {
|
|
115
|
-
// No existing range, or no existing dateFromObj, and selectedDateObject bigger then dateToObj, set selectedDate as "from"set selectedDate as "from"
|
|
116
|
-
return { from: selectedDate, to: undefined };
|
|
117
|
-
}
|
|
118
|
-
if (!dateFromObj || !dateToObj) {
|
|
119
|
-
// No existing range, set selectedDate as "from"
|
|
120
|
-
return { from: !dateFromObj ? selectedDate : dateFrom, to: !dateToObj ? selectedDate : dateTo };
|
|
121
|
-
}
|
|
122
|
-
const isWrongPeriodFrom = isWrongPeriodFn(selectedDateObj, dateToObj);
|
|
123
|
-
if (isWrongPeriodFrom) {
|
|
124
|
-
return { from: selectedDate, to: undefined };
|
|
125
|
-
}
|
|
126
|
-
const startDate = new Date(dateFromObj);
|
|
127
|
-
startDate.setHours(0, 0, 0, 0);
|
|
128
|
-
const endDate = new Date(dateToObj);
|
|
129
|
-
endDate.setHours(0, 0, 0, 0);
|
|
130
|
-
const middleDate = new Date((startDate.getTime() + endDate.getTime()) / 2);
|
|
131
|
-
if (selectedDateObj.getTime() <= middleDate.getTime()) {
|
|
132
|
-
// Closer to start date
|
|
133
|
-
return { from: selectedDate, to: dateTo };
|
|
104
|
+
// Cursor on End Date
|
|
105
|
+
if (dateFromObj && dateFromObj.getTime() < selectedDateObj.getTime()) {
|
|
106
|
+
const isWrongPeriod = isWrongPeriodFn(dateFromObj, selectedDateObj);
|
|
107
|
+
return isWrongPeriod ? { from: undefined, to: selectedDate } : { from: dateFrom, to: selectedDate };
|
|
134
108
|
}
|
|
135
|
-
//
|
|
136
|
-
return { from:
|
|
109
|
+
// Overlapping dates: selectedDate earlier than dateFrom
|
|
110
|
+
return { from: undefined, to: selectedDate };
|
|
137
111
|
};
|
|
138
112
|
exports.getCalendarRange = getCalendarRange;
|
|
@@ -28,6 +28,11 @@ export declare const getSelectableYears: (date: string, yearsRange: number, disa
|
|
|
28
28
|
export declare const isValidDate: (d?: string | Date) => boolean;
|
|
29
29
|
export declare const isValidationDateError: (date: Date, toReverseOffsetDateTime: (date: Date | string) => Date, disableFutureDates?: boolean, disablePastDates?: boolean, disableBefore?: string, disableAfter?: string) => boolean;
|
|
30
30
|
export declare const isDifferentPeriod: (date1?: Date, date2?: Date, disableFutureDates?: boolean, disablePastDates?: boolean, disableBefore?: string, disableAfter?: string) => boolean;
|
|
31
|
-
export
|
|
31
|
+
export interface IValidRange {
|
|
32
|
+
start?: Date;
|
|
33
|
+
end?: Date;
|
|
34
|
+
}
|
|
35
|
+
export declare const getValidDatesForStart: (toReverseOffsetDateTime: (date: Date | string) => Date, dateToPass: Date, endValidDate?: Date, disableFutureDates?: boolean, disablePastDates?: boolean, disableBefore?: string, disableAfter?: string) => IValidRange;
|
|
36
|
+
export declare const getValidDatesForEnd: (toReverseOffsetDateTime: (date: Date | string) => Date, dateToPass: Date, startValidDate?: Date, disableFutureDates?: boolean, disablePastDates?: boolean, disableBefore?: string, disableAfter?: string) => IValidRange;
|
|
32
37
|
export declare const getValidTime: (notValidDateToPass: Date, previousDate?: string, disableFutureDates?: boolean, disablePastDates?: boolean, disableBefore?: string, disableAfter?: string) => Date | undefined;
|
|
33
38
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValidTime = exports.
|
|
3
|
+
exports.getValidTime = exports.getValidDatesForEnd = exports.getValidDatesForStart = exports.isDifferentPeriod = exports.isValidationDateError = exports.isValidDate = exports.getSelectableYears = exports.isDisableDate = exports.isDisableYear = exports.getAvailablePeriod = exports.toDayStart = exports.setYear = exports.getSameDateOrTheLastForMonth = exports.addMonth = exports.getEndOfWeek = exports.getStartOfWeek = exports.getDayOfWeekOffset = exports.addMonths = exports.addDays = exports.addMinutes = exports.getNewEndDate = exports.getNewStartDate = exports.getCalendarMonthDates = exports.getEndOfMonth = exports.getStartOfMonth = exports.dayNames = void 0;
|
|
4
4
|
exports.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
5
5
|
const getStartOfMonth = (d) => {
|
|
6
6
|
const date = new Date(Date.parse(d));
|
|
@@ -273,85 +273,28 @@ const isDifferentPeriod = (date1, date2, disableFutureDates, disablePastDates, d
|
|
|
273
273
|
return false;
|
|
274
274
|
};
|
|
275
275
|
exports.isDifferentPeriod = isDifferentPeriod;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if ((!startValidDate && !endValidDate) || !dateToPass) {
|
|
280
|
-
return undefined;
|
|
276
|
+
const getValidDatesForStart = (toReverseOffsetDateTime, dateToPass, endValidDate, disableFutureDates = false, disablePastDates = false, disableBefore, disableAfter) => {
|
|
277
|
+
if (!endValidDate) {
|
|
278
|
+
return { start: dateToPass, end: undefined };
|
|
281
279
|
}
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (!startToPass && reversedStartDate) {
|
|
286
|
-
if (reversedStartDate >= dateToPass) {
|
|
287
|
-
const now = new Date();
|
|
288
|
-
const updateEndDate = (0, exports.addDays)(new Date(startValidDate), 1);
|
|
289
|
-
updateEndDate.setHours(dateToPass.getHours());
|
|
290
|
-
updateEndDate.setMinutes(dateToPass.getMinutes());
|
|
291
|
-
updateEndDate.setSeconds(dateToPass.getSeconds());
|
|
292
|
-
if (availablePeriod === "all" && disableFutureDates) {
|
|
293
|
-
return updateEndDate < now ? updateEndDate : now;
|
|
294
|
-
}
|
|
295
|
-
if (availablePeriod === "all" && disablePastDates) {
|
|
296
|
-
return updateEndDate >= now ? updateEndDate : undefined;
|
|
297
|
-
}
|
|
298
|
-
if (availablePeriod === "inside" && updateEndDate > new Date(disableAfter)) {
|
|
299
|
-
return new Date(disableAfter);
|
|
300
|
-
}
|
|
301
|
-
if (availablePeriod === "inside" && updateEndDate <= new Date(disableAfter)) {
|
|
302
|
-
return updateEndDate;
|
|
303
|
-
}
|
|
304
|
-
if (availablePeriod === "outside" && reversedStartDate < new Date(disableAfter)) {
|
|
305
|
-
return updateEndDate < new Date(disableAfter) ? updateEndDate : new Date(disableAfter);
|
|
306
|
-
}
|
|
307
|
-
if (availablePeriod === "outside" && reversedStartDate > new Date(disableBefore)) {
|
|
308
|
-
return updateEndDate;
|
|
309
|
-
}
|
|
310
|
-
if (availablePeriod === "before" && updateEndDate > new Date(disableAfter)) {
|
|
311
|
-
return new Date(disableAfter);
|
|
312
|
-
}
|
|
313
|
-
return availablePeriod === "all" ? updateEndDate : undefined;
|
|
314
|
-
}
|
|
315
|
-
const isDifferentPeriods = (0, exports.isDifferentPeriod)(reversedStartDate, dateToPass, disableFutureDates, disablePastDates, disableBefore, disableAfter);
|
|
316
|
-
return isDifferentPeriods ? undefined : dateToPass;
|
|
317
|
-
}
|
|
318
|
-
// Find a valid startDate
|
|
319
|
-
if (startToPass && reversedEndDate) {
|
|
320
|
-
if (reversedEndDate <= dateToPass) {
|
|
321
|
-
const now = new Date();
|
|
322
|
-
const updateStartDate = (0, exports.addDays)(new Date(endValidDate), -1);
|
|
323
|
-
updateStartDate.setHours(dateToPass.getHours());
|
|
324
|
-
updateStartDate.setMinutes(dateToPass.getMinutes());
|
|
325
|
-
updateStartDate.setSeconds(dateToPass.getSeconds());
|
|
326
|
-
if (availablePeriod === "all" && disableFutureDates) {
|
|
327
|
-
return updateStartDate > now ? undefined : updateStartDate;
|
|
328
|
-
}
|
|
329
|
-
if (availablePeriod === "all" && disablePastDates) {
|
|
330
|
-
return updateStartDate > now ? updateStartDate : now;
|
|
331
|
-
}
|
|
332
|
-
if (availablePeriod === "inside" && updateStartDate <= new Date(disableBefore)) {
|
|
333
|
-
return new Date(disableBefore);
|
|
334
|
-
}
|
|
335
|
-
if (availablePeriod === "inside" && updateStartDate < new Date(disableAfter)) {
|
|
336
|
-
return updateStartDate;
|
|
337
|
-
}
|
|
338
|
-
if (availablePeriod === "outside" && reversedEndDate > new Date(disableBefore)) {
|
|
339
|
-
return updateStartDate < new Date(disableBefore) ? new Date(disableBefore) : updateStartDate;
|
|
340
|
-
}
|
|
341
|
-
if (availablePeriod === "outside" && reversedEndDate < new Date(disableAfter)) {
|
|
342
|
-
return updateStartDate;
|
|
343
|
-
}
|
|
344
|
-
if (availablePeriod === "after" && updateStartDate < new Date(disableBefore)) {
|
|
345
|
-
return new Date(disableBefore);
|
|
346
|
-
}
|
|
347
|
-
return availablePeriod === "all" ? updateStartDate : undefined;
|
|
348
|
-
}
|
|
349
|
-
const isDifferentPeriods = (0, exports.isDifferentPeriod)(dateToPass, reversedEndDate, disableFutureDates, disablePastDates, disableBefore, disableAfter);
|
|
350
|
-
return isDifferentPeriods ? undefined : dateToPass;
|
|
280
|
+
const isDifferentPeriods = (0, exports.isDifferentPeriod)(toReverseOffsetDateTime(dateToPass), toReverseOffsetDateTime(endValidDate), disableFutureDates, disablePastDates, disableBefore, disableAfter);
|
|
281
|
+
if (dateToPass <= endValidDate && !isDifferentPeriods) {
|
|
282
|
+
return { start: dateToPass, end: endValidDate }; // in user timezone
|
|
351
283
|
}
|
|
352
|
-
return
|
|
284
|
+
return { start: dateToPass, end: dateToPass };
|
|
353
285
|
};
|
|
354
|
-
exports.
|
|
286
|
+
exports.getValidDatesForStart = getValidDatesForStart;
|
|
287
|
+
const getValidDatesForEnd = (toReverseOffsetDateTime, dateToPass, startValidDate, disableFutureDates = false, disablePastDates = false, disableBefore, disableAfter) => {
|
|
288
|
+
if (!startValidDate) {
|
|
289
|
+
return { start: undefined, end: dateToPass };
|
|
290
|
+
}
|
|
291
|
+
const isDifferentPeriods = (0, exports.isDifferentPeriod)(toReverseOffsetDateTime(startValidDate), toReverseOffsetDateTime(dateToPass), disableFutureDates, disablePastDates, disableBefore, disableAfter);
|
|
292
|
+
if (startValidDate <= dateToPass && !isDifferentPeriods) {
|
|
293
|
+
return { start: startValidDate, end: dateToPass }; // in user timezone
|
|
294
|
+
}
|
|
295
|
+
return { start: dateToPass, end: dateToPass };
|
|
296
|
+
};
|
|
297
|
+
exports.getValidDatesForEnd = getValidDatesForEnd;
|
|
355
298
|
const getValidTime = (notValidDateToPass, previousDate, disableFutureDates = false, disablePastDates = false, disableBefore, disableAfter) => {
|
|
356
299
|
const availablePeriod = (0, exports.getAvailablePeriod)(disableBefore, disableAfter);
|
|
357
300
|
if (!previousDate) {
|
|
@@ -359,40 +302,28 @@ const getValidTime = (notValidDateToPass, previousDate, disableFutureDates = fal
|
|
|
359
302
|
}
|
|
360
303
|
const now = new Date();
|
|
361
304
|
if (availablePeriod === "all" && disableFutureDates) {
|
|
362
|
-
now.setMinutes(now.getMinutes() - 1);
|
|
363
305
|
return now;
|
|
364
306
|
}
|
|
365
307
|
if (availablePeriod === "all" && disablePastDates) {
|
|
366
|
-
now.setMinutes(now.getMinutes() + 1);
|
|
367
308
|
return now;
|
|
368
309
|
}
|
|
369
310
|
if (availablePeriod === "inside" && notValidDateToPass > new Date(disableAfter)) {
|
|
370
|
-
|
|
371
|
-
newValidTime.setMinutes(newValidTime.getMinutes() - 1);
|
|
372
|
-
return newValidTime;
|
|
311
|
+
return new Date(disableAfter);
|
|
373
312
|
}
|
|
374
313
|
if (availablePeriod === "inside" && notValidDateToPass < new Date(disableBefore)) {
|
|
375
314
|
return new Date(disableBefore);
|
|
376
315
|
}
|
|
377
316
|
if (availablePeriod === "outside" && new Date(previousDate) < new Date(disableAfter)) {
|
|
378
|
-
|
|
379
|
-
newValidTime.setMinutes(newValidTime.getMinutes() - 1);
|
|
380
|
-
return newValidTime;
|
|
317
|
+
return new Date(disableAfter);
|
|
381
318
|
}
|
|
382
319
|
if (availablePeriod === "outside" && new Date(previousDate) > new Date(disableBefore)) {
|
|
383
|
-
|
|
384
|
-
newValidTime.setMinutes(newValidTime.getMinutes() + 1);
|
|
385
|
-
return newValidTime;
|
|
320
|
+
return new Date(disableBefore);
|
|
386
321
|
}
|
|
387
322
|
if (availablePeriod === "before" && notValidDateToPass > new Date(disableAfter)) {
|
|
388
|
-
|
|
389
|
-
newValidTime.setMinutes(newValidTime.getMinutes() - 1);
|
|
390
|
-
return newValidTime;
|
|
323
|
+
return new Date(disableAfter);
|
|
391
324
|
}
|
|
392
325
|
if (availablePeriod === "after" && notValidDateToPass < new Date(disableBefore)) {
|
|
393
|
-
|
|
394
|
-
newValidTime.setMinutes(newValidTime.getMinutes() + 1);
|
|
395
|
-
return newValidTime;
|
|
326
|
+
return new Date(disableBefore);
|
|
396
327
|
}
|
|
397
328
|
return undefined;
|
|
398
329
|
};
|