@uxf/datepicker 11.93.3 → 11.96.0-canary.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/hooks/use-date-range-picker.js +43 -21
- package/hooks/use-day.js +12 -10
- package/hooks/use-decade.test.js +20 -20
- package/hooks/use-month.test.js +79 -79
- package/hooks/use-year.test.js +26 -26
- package/package.json +5 -1
- package/utils/dayjs-en.d.ts +1 -0
- package/utils/dayjs-en.js +3 -3
- package/utils/get-days.test.js +125 -122
- package/utils/get-each.d.ts +1 -1
- package/utils/get-each.js +32 -6
- package/utils/get-each.test.js +16 -16
- package/utils/get-months.test.js +29 -26
- package/utils/get-years.test.js +13 -10
- package/utils/is-date-hovered.d.ts +1 -1
- package/utils/is-date-hovered.js +37 -22
- package/utils/is-date-inside-range.js +6 -1
- package/utils/is-first-or-last-selected-date.js +9 -1
- package/utils/is-in-unavailable-dates.js +3 -1
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.END_DATE = exports.START_DATE = void 0;
|
|
4
4
|
exports.useDateRangePicker = useDateRangePicker;
|
|
5
|
+
const tz_1 = require("@date-fns/tz");
|
|
6
|
+
const date_fns_1 = require("date-fns");
|
|
5
7
|
const react_1 = require("react");
|
|
6
8
|
const can_select_range_1 = require("../utils/can-select-range");
|
|
7
9
|
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
@@ -16,7 +18,10 @@ const is_start_date_1 = require("../utils/is-start-date");
|
|
|
16
18
|
const use_date_picker_navigation_1 = require("./use-date-picker-navigation");
|
|
17
19
|
exports.START_DATE = "startDate";
|
|
18
20
|
exports.END_DATE = "endDate";
|
|
19
|
-
function
|
|
21
|
+
function isBetween(date, start, end) {
|
|
22
|
+
return (0, date_fns_1.isAfter)(date, start) && (0, date_fns_1.isBefore)(date, end);
|
|
23
|
+
}
|
|
24
|
+
function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [], endDate, exactMinBookingDays = false, firstDayOfWeek = 0, focusedInput, initialVisibleMonth, isDateBlocked: isDateBlockedProps, maxBookingDate, minBookingDate, minBookingDays = 1, numberOfMonths = 2, onDatesChange, startDate, unavailableDates = [], }) {
|
|
20
25
|
const disabledDatesFromConfig = datesConfig.filter((config) => config.isDisabled).flatMap((config) => config.dates);
|
|
21
26
|
const disabledDates = [...unavailableDates, ...disabledDatesFromConfig];
|
|
22
27
|
const [activeMonths, setActiveMonths] = (0, react_1.useState)(() => startDate
|
|
@@ -24,9 +29,13 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
24
29
|
: (0, get_initial_months_1.getInitialMonths)(numberOfMonths, initialVisibleMonth || null));
|
|
25
30
|
const [hoveredDate, setHoveredDate] = (0, react_1.useState)(null);
|
|
26
31
|
const [focusedDate, setFocusedDate] = (0, react_1.useState)(startDate);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const shouldCompareBlockedDates = typeof isDateBlockedProps === "function" || disabledDates.length > 0;
|
|
33
|
+
const disabledDatesByUser = shouldCompareBlockedDates
|
|
34
|
+
? (date) => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (0, is_in_unavailable_dates_1.isInUnavailableDates)(disabledDates, date) || ((_a = isDateBlockedProps === null || isDateBlockedProps === void 0 ? void 0 : isDateBlockedProps(date)) !== null && _a !== void 0 ? _a : false);
|
|
37
|
+
}
|
|
38
|
+
: undefined;
|
|
30
39
|
const onDateFocus = (0, react_1.useCallback)((date) => {
|
|
31
40
|
setFocusedDate(date);
|
|
32
41
|
if (!focusedDate || !activeMonths.map((m) => m.month).includes((0, dayjs_en_1.dayjsEn)(date).month())) {
|
|
@@ -46,7 +55,7 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
46
55
|
minBookingDays,
|
|
47
56
|
isDateBlockedFn: disabledDatesByUser,
|
|
48
57
|
});
|
|
49
|
-
const isDateFocused = (date) =>
|
|
58
|
+
const isDateFocused = (date) => focusedDate ? (0, date_fns_1.isSameDay)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(focusedDate, dayjs_en_1.DEFAULT_TIMEZONE)) : false;
|
|
50
59
|
const _isDateHovered = (date) => (0, is_date_hovered_1.isDateHovered)({
|
|
51
60
|
date,
|
|
52
61
|
hoveredDate,
|
|
@@ -88,7 +97,7 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
88
97
|
exactMinBookingDays,
|
|
89
98
|
minBookingDate,
|
|
90
99
|
maxBookingDate,
|
|
91
|
-
isDateBlocked: disabledDatesByUser,
|
|
100
|
+
isDateBlocked: disabledDatesByUser !== null && disabledDatesByUser !== void 0 ? disabledDatesByUser : (() => false), // TODO
|
|
92
101
|
startDate: date,
|
|
93
102
|
endDate: null,
|
|
94
103
|
})) {
|
|
@@ -105,13 +114,18 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
105
114
|
!exactMinBookingDays &&
|
|
106
115
|
(0, can_select_range_1.canSelectRange)({
|
|
107
116
|
minBookingDays,
|
|
108
|
-
isDateBlocked: disabledDatesByUser,
|
|
117
|
+
isDateBlocked: disabledDatesByUser !== null && disabledDatesByUser !== void 0 ? disabledDatesByUser : (() => false), // TODO
|
|
109
118
|
startDate: date,
|
|
110
119
|
endDate: null,
|
|
111
120
|
})) ||
|
|
112
121
|
(focusedInput === exports.START_DATE &&
|
|
113
122
|
!exactMinBookingDays &&
|
|
114
|
-
(0, can_select_range_1.canSelectRange)({
|
|
123
|
+
(0, can_select_range_1.canSelectRange)({
|
|
124
|
+
minBookingDays,
|
|
125
|
+
isDateBlocked: disabledDatesByUser !== null && disabledDatesByUser !== void 0 ? disabledDatesByUser : (() => false),
|
|
126
|
+
endDate,
|
|
127
|
+
startDate: date,
|
|
128
|
+
}))) {
|
|
115
129
|
onDatesChange({
|
|
116
130
|
endDate: null,
|
|
117
131
|
startDate: date,
|
|
@@ -122,7 +136,7 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
122
136
|
!exactMinBookingDays &&
|
|
123
137
|
(0, can_select_range_1.canSelectRange)({
|
|
124
138
|
minBookingDays,
|
|
125
|
-
isDateBlocked: disabledDatesByUser,
|
|
139
|
+
isDateBlocked: disabledDatesByUser !== null && disabledDatesByUser !== void 0 ? disabledDatesByUser : (() => false), // TODO
|
|
126
140
|
endDate: null,
|
|
127
141
|
startDate: date,
|
|
128
142
|
})) {
|
|
@@ -136,7 +150,12 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
136
150
|
startDate &&
|
|
137
151
|
!(0, dayjs_en_1.dayjsEn)(date).isBefore(startDate) &&
|
|
138
152
|
!exactMinBookingDays &&
|
|
139
|
-
(0, can_select_range_1.canSelectRange)({
|
|
153
|
+
(0, can_select_range_1.canSelectRange)({
|
|
154
|
+
minBookingDays,
|
|
155
|
+
isDateBlocked: disabledDatesByUser !== null && disabledDatesByUser !== void 0 ? disabledDatesByUser : (() => false),
|
|
156
|
+
startDate,
|
|
157
|
+
endDate: date,
|
|
158
|
+
})) {
|
|
140
159
|
onDatesChange({
|
|
141
160
|
startDate,
|
|
142
161
|
endDate: date,
|
|
@@ -155,7 +174,7 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
155
174
|
exactMinBookingDays,
|
|
156
175
|
minBookingDate,
|
|
157
176
|
maxBookingDate,
|
|
158
|
-
isDateBlocked: disabledDatesByUser,
|
|
177
|
+
isDateBlocked: disabledDatesByUser !== null && disabledDatesByUser !== void 0 ? disabledDatesByUser : (() => false), // TODO
|
|
159
178
|
startDate: start,
|
|
160
179
|
endDate: end,
|
|
161
180
|
})) {
|
|
@@ -177,20 +196,21 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
177
196
|
setHoveredDate(null);
|
|
178
197
|
}
|
|
179
198
|
else {
|
|
180
|
-
const isNotBlocked = !_isDateBlocked(date) ||
|
|
199
|
+
const isNotBlocked = !_isDateBlocked(date) ||
|
|
200
|
+
(startDate && (0, date_fns_1.isSameDay)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(startDate, dayjs_en_1.DEFAULT_TIMEZONE)));
|
|
181
201
|
const isHoveredDateAfterOrEqualMinDate = minBookingDate
|
|
182
|
-
? !(0,
|
|
202
|
+
? !(0, date_fns_1.isBefore)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(minBookingDate, dayjs_en_1.DEFAULT_TIMEZONE))
|
|
203
|
+
: true;
|
|
204
|
+
const isHoveredDateBeforeOrEqualMaxDate = maxBookingDate
|
|
205
|
+
? !(0, date_fns_1.isAfter)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(maxBookingDate, dayjs_en_1.DEFAULT_TIMEZONE))
|
|
183
206
|
: true;
|
|
184
|
-
const isHoveredDateBeforeOrEqualMaxDate = maxBookingDate ? !(0, dayjs_en_1.dayjsEn)(date).isAfter(maxBookingDate) : true;
|
|
185
207
|
// Exact minimal booking days
|
|
186
|
-
const potentialEndDate = (0,
|
|
187
|
-
.add(minBookingDays - 1, "day")
|
|
188
|
-
.toDate();
|
|
208
|
+
const potentialEndDate = (0, date_fns_1.addDays)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), minBookingDays - 1);
|
|
189
209
|
const isPotentialEndDateAfterOrEqualMinDate = minBookingDate
|
|
190
|
-
? !(0,
|
|
210
|
+
? !(0, date_fns_1.isBefore)(potentialEndDate, new tz_1.TZDate(minBookingDate, dayjs_en_1.DEFAULT_TIMEZONE))
|
|
191
211
|
: true;
|
|
192
212
|
const isPotentialEndDateBeforeOrEqualMaxDate = maxBookingDate
|
|
193
|
-
? !(0,
|
|
213
|
+
? !(0, date_fns_1.isAfter)(potentialEndDate, new tz_1.TZDate(maxBookingDate, dayjs_en_1.DEFAULT_TIMEZONE))
|
|
194
214
|
: true;
|
|
195
215
|
const isExactAndInRange = exactMinBookingDays &&
|
|
196
216
|
minBookingDays > 1 &&
|
|
@@ -206,9 +226,11 @@ function useDateRangePicker({ changeActiveMonthOnSelect = false, datesConfig = [
|
|
|
206
226
|
isHoveredDateBeforeOrEqualMaxDate;
|
|
207
227
|
// Is start date hovered and in range
|
|
208
228
|
const isMinBookingDaysInRange = minBookingDays > 1 && startDate
|
|
209
|
-
? (
|
|
229
|
+
? isBetween(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(startDate, dayjs_en_1.DEFAULT_TIMEZONE), (0, date_fns_1.addDays)(new tz_1.TZDate(startDate, dayjs_en_1.DEFAULT_TIMEZONE), minBookingDays - 2))
|
|
210
230
|
: true;
|
|
211
|
-
const isStartDateHoveredAndInRange = startDate &&
|
|
231
|
+
const isStartDateHoveredAndInRange = startDate &&
|
|
232
|
+
(0, date_fns_1.isSameDay)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(startDate, dayjs_en_1.DEFAULT_TIMEZONE)) &&
|
|
233
|
+
isMinBookingDaysInRange;
|
|
212
234
|
if (isNotBlocked && (isExactAndInRange || isInRange || isStartDateHoveredAndInRange)) {
|
|
213
235
|
setHoveredDate(date);
|
|
214
236
|
}
|
package/hooks/use-day.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useDay = useDay;
|
|
4
|
+
const tz_1 = require("@date-fns/tz");
|
|
4
5
|
const empty_array_1 = require("@uxf/core/constants/empty-array");
|
|
6
|
+
const date_fns_1 = require("date-fns");
|
|
5
7
|
const react_1 = require("react");
|
|
6
8
|
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
7
9
|
const get_date_invervals_1 = require("../utils/get-date-invervals");
|
|
@@ -13,7 +15,7 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
13
15
|
const onClick = (0, react_1.useCallback)(() => onDateSelect(date), [date, onDateSelect]);
|
|
14
16
|
const onMouseEnter = (0, react_1.useCallback)(() => onDateHover(date), [date, onDateHover]);
|
|
15
17
|
const disabled = isDateBlocked(date) && !isDateHovered(date);
|
|
16
|
-
const isToday = (0,
|
|
18
|
+
const isToday = (0, date_fns_1.isSameDay)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(new Date(), dayjs_en_1.DEFAULT_TIMEZONE));
|
|
17
19
|
(0, react_1.useEffect)(() => {
|
|
18
20
|
if (dayRef && dayRef.current && isDateFocused(date)) {
|
|
19
21
|
dayRef.current.focus({
|
|
@@ -26,28 +28,28 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
26
28
|
e.preventDefault();
|
|
27
29
|
switch (e.key) {
|
|
28
30
|
case "ArrowRight":
|
|
29
|
-
onDateFocus((0,
|
|
31
|
+
onDateFocus((0, date_fns_1.addDays)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), 1));
|
|
30
32
|
break;
|
|
31
33
|
case "ArrowLeft":
|
|
32
|
-
onDateFocus((0,
|
|
34
|
+
onDateFocus((0, date_fns_1.subDays)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), 1));
|
|
33
35
|
break;
|
|
34
36
|
case "ArrowUp":
|
|
35
|
-
onDateFocus((0,
|
|
37
|
+
onDateFocus((0, date_fns_1.subDays)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), 7));
|
|
36
38
|
break;
|
|
37
39
|
case "ArrowDown":
|
|
38
|
-
onDateFocus((0,
|
|
40
|
+
onDateFocus((0, date_fns_1.addDays)(new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE), 7));
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
}, [date, onDateFocus]);
|
|
43
45
|
const dateIntervals = (0, get_date_invervals_1.getDateIntervals)(disabledDates);
|
|
44
46
|
const _isFirstUnavailableDate = () => {
|
|
45
|
-
return dateIntervals.some((interval) => (0,
|
|
47
|
+
return dateIntervals.some((interval) => (0, date_fns_1.isSameDay)(new tz_1.TZDate(interval.start, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE)));
|
|
46
48
|
};
|
|
47
49
|
const _isLastUnavailableDate = () => {
|
|
48
|
-
return dateIntervals.some((interval) => (0,
|
|
50
|
+
return dateIntervals.some((interval) => (0, date_fns_1.isSameDay)(new tz_1.TZDate(interval.end, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE)));
|
|
49
51
|
};
|
|
50
|
-
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.dates.some((configDay) => (0,
|
|
52
|
+
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.dates.some((configDay) => (0, date_fns_1.isSameDay)(new tz_1.TZDate(configDay, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE))));
|
|
51
53
|
const flags = applicableDatesConfigs === null || applicableDatesConfigs === void 0 ? void 0 : applicableDatesConfigs.reduce((acc, curr) => {
|
|
52
54
|
if (!curr.flag) {
|
|
53
55
|
return acc;
|
|
@@ -55,8 +57,8 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
55
57
|
const intervals = (0, get_date_invervals_1.getDateIntervals)(curr.dates);
|
|
56
58
|
acc.push({
|
|
57
59
|
flag: curr.flag,
|
|
58
|
-
isFirst: intervals.some((interval) => (0,
|
|
59
|
-
isLast: intervals.some((interval) => (0,
|
|
60
|
+
isFirst: intervals.some((interval) => (0, date_fns_1.isSameDay)(new tz_1.TZDate(interval.start, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE))),
|
|
61
|
+
isLast: intervals.some((interval) => (0, date_fns_1.isSameDay)(new tz_1.TZDate(interval.end, dayjs_en_1.DEFAULT_TIMEZONE), new tz_1.TZDate(date, dayjs_en_1.DEFAULT_TIMEZONE))),
|
|
60
62
|
});
|
|
61
63
|
return acc;
|
|
62
64
|
}, []);
|
package/hooks/use-decade.test.js
CHANGED
|
@@ -8,16 +8,16 @@ test("useDecade", () => {
|
|
|
8
8
|
year: 2021,
|
|
9
9
|
}));
|
|
10
10
|
expect(result.current.decadeLabel).toBe("2017 – 2025");
|
|
11
|
-
expect(result.current.years).toStrictEqual([
|
|
12
|
-
{ date: new Date("2017-01-01T00:00:00+01:00"), yearLabel: "2017" },
|
|
13
|
-
{ date: new Date("2018-01-01T00:00:00+01:00"), yearLabel: "2018" },
|
|
14
|
-
{ date: new Date("2019-01-01T00:00:00+01:00"), yearLabel: "2019" },
|
|
15
|
-
{ date: new Date("2020-01-01T00:00:00+01:00"), yearLabel: "2020" },
|
|
16
|
-
{ date: new Date("2021-01-01T00:00:00+01:00"), yearLabel: "2021" },
|
|
17
|
-
{ date: new Date("2022-01-01T00:00:00+01:00"), yearLabel: "2022" },
|
|
18
|
-
{ date: new Date("2023-01-01T00:00:00+01:00"), yearLabel: "2023" },
|
|
19
|
-
{ date: new Date("2024-01-01T00:00:00+01:00"), yearLabel: "2024" },
|
|
20
|
-
{ date: new Date("2025-01-01T00:00:00+01:00"), yearLabel: "2025" },
|
|
11
|
+
expect(result.current.years.map((d) => ({ ...d, date: d.date.toUTCString() }))).toStrictEqual([
|
|
12
|
+
{ date: new Date("2017-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2017" },
|
|
13
|
+
{ date: new Date("2018-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2018" },
|
|
14
|
+
{ date: new Date("2019-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2019" },
|
|
15
|
+
{ date: new Date("2020-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2020" },
|
|
16
|
+
{ date: new Date("2021-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2021" },
|
|
17
|
+
{ date: new Date("2022-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2022" },
|
|
18
|
+
{ date: new Date("2023-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2023" },
|
|
19
|
+
{ date: new Date("2024-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2024" },
|
|
20
|
+
{ date: new Date("2025-01-01T00:00:00+01:00").toUTCString(), yearLabel: "2025" },
|
|
21
21
|
]);
|
|
22
22
|
});
|
|
23
23
|
test("useDecade with custom formats", () => {
|
|
@@ -27,15 +27,15 @@ test("useDecade with custom formats", () => {
|
|
|
27
27
|
yearLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("YY"),
|
|
28
28
|
}));
|
|
29
29
|
expect(result.current.decadeLabel).toBe("17 - 25");
|
|
30
|
-
expect(result.current.years).toStrictEqual([
|
|
31
|
-
{ date: new Date("2017-01-01T00:00:00+01:00"), yearLabel: "17" },
|
|
32
|
-
{ date: new Date("2018-01-01T00:00:00+01:00"), yearLabel: "18" },
|
|
33
|
-
{ date: new Date("2019-01-01T00:00:00+01:00"), yearLabel: "19" },
|
|
34
|
-
{ date: new Date("2020-01-01T00:00:00+01:00"), yearLabel: "20" },
|
|
35
|
-
{ date: new Date("2021-01-01T00:00:00+01:00"), yearLabel: "21" },
|
|
36
|
-
{ date: new Date("2022-01-01T00:00:00+01:00"), yearLabel: "22" },
|
|
37
|
-
{ date: new Date("2023-01-01T00:00:00+01:00"), yearLabel: "23" },
|
|
38
|
-
{ date: new Date("2024-01-01T00:00:00+01:00"), yearLabel: "24" },
|
|
39
|
-
{ date: new Date("2025-01-01T00:00:00+01:00"), yearLabel: "25" },
|
|
30
|
+
expect(result.current.years.map((d) => ({ ...d, date: d.date.toUTCString() }))).toStrictEqual([
|
|
31
|
+
{ date: new Date("2017-01-01T00:00:00+01:00").toUTCString(), yearLabel: "17" },
|
|
32
|
+
{ date: new Date("2018-01-01T00:00:00+01:00").toUTCString(), yearLabel: "18" },
|
|
33
|
+
{ date: new Date("2019-01-01T00:00:00+01:00").toUTCString(), yearLabel: "19" },
|
|
34
|
+
{ date: new Date("2020-01-01T00:00:00+01:00").toUTCString(), yearLabel: "20" },
|
|
35
|
+
{ date: new Date("2021-01-01T00:00:00+01:00").toUTCString(), yearLabel: "21" },
|
|
36
|
+
{ date: new Date("2022-01-01T00:00:00+01:00").toUTCString(), yearLabel: "22" },
|
|
37
|
+
{ date: new Date("2023-01-01T00:00:00+01:00").toUTCString(), yearLabel: "23" },
|
|
38
|
+
{ date: new Date("2024-01-01T00:00:00+01:00").toUTCString(), yearLabel: "24" },
|
|
39
|
+
{ date: new Date("2025-01-01T00:00:00+01:00").toUTCString(), yearLabel: "25" },
|
|
40
40
|
]);
|
|
41
41
|
});
|
package/hooks/use-month.test.js
CHANGED
|
@@ -9,49 +9,49 @@ test("useMonth", () => {
|
|
|
9
9
|
month: 0,
|
|
10
10
|
}));
|
|
11
11
|
expect(result.current.monthLabel).toBe("January 2021");
|
|
12
|
-
expect(result.current.days).toStrictEqual([
|
|
13
|
-
{ dayLabel: "27", date: new Date("2020-12-27T00:00:00+01:00"), currentMonth: false },
|
|
14
|
-
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00"), currentMonth: false },
|
|
15
|
-
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00"), currentMonth: false },
|
|
16
|
-
{ dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00"), currentMonth: false },
|
|
17
|
-
{ dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00"), currentMonth: false },
|
|
18
|
-
{ dayLabel: "01", date: new Date("2021-01-01T00:00:00+01:00"), currentMonth: true },
|
|
19
|
-
{ dayLabel: "02", date: new Date("2021-01-02T00:00:00+01:00"), currentMonth: true },
|
|
20
|
-
{ dayLabel: "03", date: new Date("2021-01-03T00:00:00+01:00"), currentMonth: true },
|
|
21
|
-
{ dayLabel: "04", date: new Date("2021-01-04T00:00:00+01:00"), currentMonth: true },
|
|
22
|
-
{ dayLabel: "05", date: new Date("2021-01-05T00:00:00+01:00"), currentMonth: true },
|
|
23
|
-
{ dayLabel: "06", date: new Date("2021-01-06T00:00:00+01:00"), currentMonth: true },
|
|
24
|
-
{ dayLabel: "07", date: new Date("2021-01-07T00:00:00+01:00"), currentMonth: true },
|
|
25
|
-
{ dayLabel: "08", date: new Date("2021-01-08T00:00:00+01:00"), currentMonth: true },
|
|
26
|
-
{ dayLabel: "09", date: new Date("2021-01-09T00:00:00+01:00"), currentMonth: true },
|
|
27
|
-
{ dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00"), currentMonth: true },
|
|
28
|
-
{ dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00"), currentMonth: true },
|
|
29
|
-
{ dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00"), currentMonth: true },
|
|
30
|
-
{ dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00"), currentMonth: true },
|
|
31
|
-
{ dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00"), currentMonth: true },
|
|
32
|
-
{ dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00"), currentMonth: true },
|
|
33
|
-
{ dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00"), currentMonth: true },
|
|
34
|
-
{ dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00"), currentMonth: true },
|
|
35
|
-
{ dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00"), currentMonth: true },
|
|
36
|
-
{ dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00"), currentMonth: true },
|
|
37
|
-
{ dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00"), currentMonth: true },
|
|
38
|
-
{ dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00"), currentMonth: true },
|
|
39
|
-
{ dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00"), currentMonth: true },
|
|
40
|
-
{ dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00"), currentMonth: true },
|
|
41
|
-
{ dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00"), currentMonth: true },
|
|
42
|
-
{ dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00"), currentMonth: true },
|
|
43
|
-
{ dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00"), currentMonth: true },
|
|
44
|
-
{ dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00"), currentMonth: true },
|
|
45
|
-
{ dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00"), currentMonth: true },
|
|
46
|
-
{ dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00"), currentMonth: true },
|
|
47
|
-
{ dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00"), currentMonth: true },
|
|
48
|
-
{ dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00"), currentMonth: true },
|
|
49
|
-
{ dayLabel: "01", date: new Date("2021-02-01T00:00:00+01:00"), currentMonth: false },
|
|
50
|
-
{ dayLabel: "02", date: new Date("2021-02-02T00:00:00+01:00"), currentMonth: false },
|
|
51
|
-
{ dayLabel: "03", date: new Date("2021-02-03T00:00:00+01:00"), currentMonth: false },
|
|
52
|
-
{ dayLabel: "04", date: new Date("2021-02-04T00:00:00+01:00"), currentMonth: false },
|
|
53
|
-
{ dayLabel: "05", date: new Date("2021-02-05T00:00:00+01:00"), currentMonth: false },
|
|
54
|
-
{ dayLabel: "06", date: new Date("2021-02-06T00:00:00+01:00"), currentMonth: false },
|
|
12
|
+
expect(result.current.days.map((d) => ({ ...d, date: d.date.toUTCString() }))).toStrictEqual([
|
|
13
|
+
{ dayLabel: "27", date: new Date("2020-12-27T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
14
|
+
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
15
|
+
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
16
|
+
{ dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
17
|
+
{ dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
18
|
+
{ dayLabel: "01", date: new Date("2021-01-01T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
19
|
+
{ dayLabel: "02", date: new Date("2021-01-02T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
20
|
+
{ dayLabel: "03", date: new Date("2021-01-03T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
21
|
+
{ dayLabel: "04", date: new Date("2021-01-04T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
22
|
+
{ dayLabel: "05", date: new Date("2021-01-05T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
23
|
+
{ dayLabel: "06", date: new Date("2021-01-06T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
24
|
+
{ dayLabel: "07", date: new Date("2021-01-07T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
25
|
+
{ dayLabel: "08", date: new Date("2021-01-08T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
26
|
+
{ dayLabel: "09", date: new Date("2021-01-09T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
27
|
+
{ dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
28
|
+
{ dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
29
|
+
{ dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
30
|
+
{ dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
31
|
+
{ dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
32
|
+
{ dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
33
|
+
{ dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
34
|
+
{ dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
35
|
+
{ dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
36
|
+
{ dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
37
|
+
{ dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
38
|
+
{ dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
39
|
+
{ dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
40
|
+
{ dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
41
|
+
{ dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
42
|
+
{ dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
43
|
+
{ dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
44
|
+
{ dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
45
|
+
{ dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
46
|
+
{ dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
47
|
+
{ dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
48
|
+
{ dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
49
|
+
{ dayLabel: "01", date: new Date("2021-02-01T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
50
|
+
{ dayLabel: "02", date: new Date("2021-02-02T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
51
|
+
{ dayLabel: "03", date: new Date("2021-02-03T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
52
|
+
{ dayLabel: "04", date: new Date("2021-02-04T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
53
|
+
{ dayLabel: "05", date: new Date("2021-02-05T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
54
|
+
{ dayLabel: "06", date: new Date("2021-02-06T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
55
55
|
]);
|
|
56
56
|
expect(result.current.weekdayLabels).toStrictEqual(["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]);
|
|
57
57
|
});
|
|
@@ -65,42 +65,42 @@ test("useMonth with custom formats and firstDayOfWeek", () => {
|
|
|
65
65
|
weekdayLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("dddd"),
|
|
66
66
|
}));
|
|
67
67
|
expect(result.current.monthLabel).toBe("01");
|
|
68
|
-
expect(result.current.days).toStrictEqual([
|
|
69
|
-
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00"), currentMonth: false },
|
|
70
|
-
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00"), currentMonth: false },
|
|
71
|
-
{ dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00"), currentMonth: false },
|
|
72
|
-
{ dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00"), currentMonth: false },
|
|
73
|
-
{ dayLabel: "1", date: new Date("2021-01-01T00:00:00+01:00"), currentMonth: true },
|
|
74
|
-
{ dayLabel: "2", date: new Date("2021-01-02T00:00:00+01:00"), currentMonth: true },
|
|
75
|
-
{ dayLabel: "3", date: new Date("2021-01-03T00:00:00+01:00"), currentMonth: true },
|
|
76
|
-
{ dayLabel: "4", date: new Date("2021-01-04T00:00:00+01:00"), currentMonth: true },
|
|
77
|
-
{ dayLabel: "5", date: new Date("2021-01-05T00:00:00+01:00"), currentMonth: true },
|
|
78
|
-
{ dayLabel: "6", date: new Date("2021-01-06T00:00:00+01:00"), currentMonth: true },
|
|
79
|
-
{ dayLabel: "7", date: new Date("2021-01-07T00:00:00+01:00"), currentMonth: true },
|
|
80
|
-
{ dayLabel: "8", date: new Date("2021-01-08T00:00:00+01:00"), currentMonth: true },
|
|
81
|
-
{ dayLabel: "9", date: new Date("2021-01-09T00:00:00+01:00"), currentMonth: true },
|
|
82
|
-
{ dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00"), currentMonth: true },
|
|
83
|
-
{ dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00"), currentMonth: true },
|
|
84
|
-
{ dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00"), currentMonth: true },
|
|
85
|
-
{ dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00"), currentMonth: true },
|
|
86
|
-
{ dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00"), currentMonth: true },
|
|
87
|
-
{ dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00"), currentMonth: true },
|
|
88
|
-
{ dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00"), currentMonth: true },
|
|
89
|
-
{ dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00"), currentMonth: true },
|
|
90
|
-
{ dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00"), currentMonth: true },
|
|
91
|
-
{ dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00"), currentMonth: true },
|
|
92
|
-
{ dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00"), currentMonth: true },
|
|
93
|
-
{ dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00"), currentMonth: true },
|
|
94
|
-
{ dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00"), currentMonth: true },
|
|
95
|
-
{ dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00"), currentMonth: true },
|
|
96
|
-
{ dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00"), currentMonth: true },
|
|
97
|
-
{ dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00"), currentMonth: true },
|
|
98
|
-
{ dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00"), currentMonth: true },
|
|
99
|
-
{ dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00"), currentMonth: true },
|
|
100
|
-
{ dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00"), currentMonth: true },
|
|
101
|
-
{ dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00"), currentMonth: true },
|
|
102
|
-
{ dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00"), currentMonth: true },
|
|
103
|
-
{ dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00"), currentMonth: true },
|
|
68
|
+
expect(result.current.days.map((d) => ({ ...d, date: d.date.toUTCString() }))).toStrictEqual([
|
|
69
|
+
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
70
|
+
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
71
|
+
{ dayLabel: "30", date: new Date("2020-12-30T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
72
|
+
{ dayLabel: "31", date: new Date("2020-12-31T00:00:00+01:00").toUTCString(), currentMonth: false },
|
|
73
|
+
{ dayLabel: "1", date: new Date("2021-01-01T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
74
|
+
{ dayLabel: "2", date: new Date("2021-01-02T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
75
|
+
{ dayLabel: "3", date: new Date("2021-01-03T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
76
|
+
{ dayLabel: "4", date: new Date("2021-01-04T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
77
|
+
{ dayLabel: "5", date: new Date("2021-01-05T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
78
|
+
{ dayLabel: "6", date: new Date("2021-01-06T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
79
|
+
{ dayLabel: "7", date: new Date("2021-01-07T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
80
|
+
{ dayLabel: "8", date: new Date("2021-01-08T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
81
|
+
{ dayLabel: "9", date: new Date("2021-01-09T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
82
|
+
{ dayLabel: "10", date: new Date("2021-01-10T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
83
|
+
{ dayLabel: "11", date: new Date("2021-01-11T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
84
|
+
{ dayLabel: "12", date: new Date("2021-01-12T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
85
|
+
{ dayLabel: "13", date: new Date("2021-01-13T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
86
|
+
{ dayLabel: "14", date: new Date("2021-01-14T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
87
|
+
{ dayLabel: "15", date: new Date("2021-01-15T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
88
|
+
{ dayLabel: "16", date: new Date("2021-01-16T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
89
|
+
{ dayLabel: "17", date: new Date("2021-01-17T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
90
|
+
{ dayLabel: "18", date: new Date("2021-01-18T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
91
|
+
{ dayLabel: "19", date: new Date("2021-01-19T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
92
|
+
{ dayLabel: "20", date: new Date("2021-01-20T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
93
|
+
{ dayLabel: "21", date: new Date("2021-01-21T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
94
|
+
{ dayLabel: "22", date: new Date("2021-01-22T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
95
|
+
{ dayLabel: "23", date: new Date("2021-01-23T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
96
|
+
{ dayLabel: "24", date: new Date("2021-01-24T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
97
|
+
{ dayLabel: "25", date: new Date("2021-01-25T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
98
|
+
{ dayLabel: "26", date: new Date("2021-01-26T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
99
|
+
{ dayLabel: "27", date: new Date("2021-01-27T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
100
|
+
{ dayLabel: "28", date: new Date("2021-01-28T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
101
|
+
{ dayLabel: "29", date: new Date("2021-01-29T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
102
|
+
{ dayLabel: "30", date: new Date("2021-01-30T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
103
|
+
{ dayLabel: "31", date: new Date("2021-01-31T00:00:00+01:00").toUTCString(), currentMonth: true },
|
|
104
104
|
]);
|
|
105
105
|
expect(result.current.weekdayLabels).toStrictEqual([
|
|
106
106
|
"Monday",
|
package/hooks/use-year.test.js
CHANGED
|
@@ -8,19 +8,19 @@ test("useYear", () => {
|
|
|
8
8
|
year: 2021,
|
|
9
9
|
}));
|
|
10
10
|
expect(result.current.yearLabel).toBe("2021");
|
|
11
|
-
expect(result.current.months).toStrictEqual([
|
|
12
|
-
{ date: new Date("2021-01-01T00:00:00+01:00"), monthLabel: "January" },
|
|
13
|
-
{ date: new Date("2021-02-01T00:00:00+01:00"), monthLabel: "February" },
|
|
14
|
-
{ date: new Date("2021-03-01T00:00:00+01:00"), monthLabel: "March" },
|
|
15
|
-
{ date: new Date("2021-04-01T00:00:00+02:00"), monthLabel: "April" },
|
|
16
|
-
{ date: new Date("2021-05-01T00:00:00+02:00"), monthLabel: "May" },
|
|
17
|
-
{ date: new Date("2021-06-01T00:00:00+02:00"), monthLabel: "June" },
|
|
18
|
-
{ date: new Date("2021-07-01T00:00:00+02:00"), monthLabel: "July" },
|
|
19
|
-
{ date: new Date("2021-08-01T00:00:00+02:00"), monthLabel: "August" },
|
|
20
|
-
{ date: new Date("2021-09-01T00:00:00+02:00"), monthLabel: "September" },
|
|
21
|
-
{ date: new Date("2021-10-01T00:00:00+02:00"), monthLabel: "October" },
|
|
22
|
-
{ date: new Date("2021-11-01T00:00:00+01:00"), monthLabel: "November" },
|
|
23
|
-
{ date: new Date("2021-12-01T00:00:00+01:00"), monthLabel: "December" },
|
|
11
|
+
expect(result.current.months.map((d) => ({ ...d, date: d.date.toUTCString() }))).toStrictEqual([
|
|
12
|
+
{ date: new Date("2021-01-01T00:00:00+01:00").toUTCString(), monthLabel: "January" },
|
|
13
|
+
{ date: new Date("2021-02-01T00:00:00+01:00").toUTCString(), monthLabel: "February" },
|
|
14
|
+
{ date: new Date("2021-03-01T00:00:00+01:00").toUTCString(), monthLabel: "March" },
|
|
15
|
+
{ date: new Date("2021-04-01T00:00:00+02:00").toUTCString(), monthLabel: "April" },
|
|
16
|
+
{ date: new Date("2021-05-01T00:00:00+02:00").toUTCString(), monthLabel: "May" },
|
|
17
|
+
{ date: new Date("2021-06-01T00:00:00+02:00").toUTCString(), monthLabel: "June" },
|
|
18
|
+
{ date: new Date("2021-07-01T00:00:00+02:00").toUTCString(), monthLabel: "July" },
|
|
19
|
+
{ date: new Date("2021-08-01T00:00:00+02:00").toUTCString(), monthLabel: "August" },
|
|
20
|
+
{ date: new Date("2021-09-01T00:00:00+02:00").toUTCString(), monthLabel: "September" },
|
|
21
|
+
{ date: new Date("2021-10-01T00:00:00+02:00").toUTCString(), monthLabel: "October" },
|
|
22
|
+
{ date: new Date("2021-11-01T00:00:00+01:00").toUTCString(), monthLabel: "November" },
|
|
23
|
+
{ date: new Date("2021-12-01T00:00:00+01:00").toUTCString(), monthLabel: "December" },
|
|
24
24
|
]);
|
|
25
25
|
});
|
|
26
26
|
test("useYear with custom formats", () => {
|
|
@@ -30,18 +30,18 @@ test("useYear with custom formats", () => {
|
|
|
30
30
|
yearLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("YY"),
|
|
31
31
|
}));
|
|
32
32
|
expect(result.current.yearLabel).toBe("21");
|
|
33
|
-
expect(result.current.months).toStrictEqual([
|
|
34
|
-
{ date: new Date("2021-01-01T00:00:00+01:00"), monthLabel: "01" },
|
|
35
|
-
{ date: new Date("2021-02-01T00:00:00+01:00"), monthLabel: "02" },
|
|
36
|
-
{ date: new Date("2021-03-01T00:00:00+01:00"), monthLabel: "03" },
|
|
37
|
-
{ date: new Date("2021-04-01T00:00:00+02:00"), monthLabel: "04" },
|
|
38
|
-
{ date: new Date("2021-05-01T00:00:00+02:00"), monthLabel: "05" },
|
|
39
|
-
{ date: new Date("2021-06-01T00:00:00+02:00"), monthLabel: "06" },
|
|
40
|
-
{ date: new Date("2021-07-01T00:00:00+02:00"), monthLabel: "07" },
|
|
41
|
-
{ date: new Date("2021-08-01T00:00:00+02:00"), monthLabel: "08" },
|
|
42
|
-
{ date: new Date("2021-09-01T00:00:00+02:00"), monthLabel: "09" },
|
|
43
|
-
{ date: new Date("2021-10-01T00:00:00+02:00"), monthLabel: "10" },
|
|
44
|
-
{ date: new Date("2021-11-01T00:00:00+01:00"), monthLabel: "11" },
|
|
45
|
-
{ date: new Date("2021-12-01T00:00:00+01:00"), monthLabel: "12" },
|
|
33
|
+
expect(result.current.months.map((d) => ({ ...d, date: d.date.toUTCString() }))).toStrictEqual([
|
|
34
|
+
{ date: new Date("2021-01-01T00:00:00+01:00").toUTCString(), monthLabel: "01" },
|
|
35
|
+
{ date: new Date("2021-02-01T00:00:00+01:00").toUTCString(), monthLabel: "02" },
|
|
36
|
+
{ date: new Date("2021-03-01T00:00:00+01:00").toUTCString(), monthLabel: "03" },
|
|
37
|
+
{ date: new Date("2021-04-01T00:00:00+02:00").toUTCString(), monthLabel: "04" },
|
|
38
|
+
{ date: new Date("2021-05-01T00:00:00+02:00").toUTCString(), monthLabel: "05" },
|
|
39
|
+
{ date: new Date("2021-06-01T00:00:00+02:00").toUTCString(), monthLabel: "06" },
|
|
40
|
+
{ date: new Date("2021-07-01T00:00:00+02:00").toUTCString(), monthLabel: "07" },
|
|
41
|
+
{ date: new Date("2021-08-01T00:00:00+02:00").toUTCString(), monthLabel: "08" },
|
|
42
|
+
{ date: new Date("2021-09-01T00:00:00+02:00").toUTCString(), monthLabel: "09" },
|
|
43
|
+
{ date: new Date("2021-10-01T00:00:00+02:00").toUTCString(), monthLabel: "10" },
|
|
44
|
+
{ date: new Date("2021-11-01T00:00:00+01:00").toUTCString(), monthLabel: "11" },
|
|
45
|
+
{ date: new Date("2021-12-01T00:00:00+01:00").toUTCString(), monthLabel: "12" },
|
|
46
46
|
]);
|
|
47
47
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/datepicker",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.96.0-canary.1",
|
|
4
4
|
"description": "A set of React hooks to create an awesome datepicker.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"url": "https://gitlab.com/uxf-npm/datepicker/issues"
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://gitlab.com/uxf-npm/datepicker#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"date-fns": "4.1.0",
|
|
25
|
+
"@date-fns/tz": "1.4.1"
|
|
26
|
+
},
|
|
23
27
|
"peerDependencies": {
|
|
24
28
|
"react": ">=18.2.0",
|
|
25
29
|
"react-dom": ">=18.2.0"
|
package/utils/dayjs-en.d.ts
CHANGED
package/utils/dayjs-en.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.dayjsEn = void 0;
|
|
39
|
+
exports.dayjsEn = exports.DEFAULT_TIMEZONE = void 0;
|
|
40
40
|
const dayjs_1 = __importStar(require("dayjs"));
|
|
41
41
|
require("dayjs/locale/en");
|
|
42
42
|
const isBetween_1 = __importDefault(require("dayjs/plugin/isBetween"));
|
|
@@ -45,8 +45,8 @@ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
|
45
45
|
(0, dayjs_1.extend)(isBetween_1.default);
|
|
46
46
|
(0, dayjs_1.extend)(timezone_1.default);
|
|
47
47
|
(0, dayjs_1.extend)(utc_1.default);
|
|
48
|
-
|
|
48
|
+
exports.DEFAULT_TIMEZONE = "Europe/Prague";
|
|
49
49
|
const dayjsEn = (value) => {
|
|
50
|
-
return dayjs_1.default.tz(value, DEFAULT_TIMEZONE).locale("en");
|
|
50
|
+
return dayjs_1.default.tz(value, exports.DEFAULT_TIMEZONE).locale("en");
|
|
51
51
|
};
|
|
52
52
|
exports.dayjsEn = dayjsEn;
|