@uxf/datepicker 11.90.0 → 11.92.0
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-picker.test.js +2 -2
- package/hooks/use-date-range-picker.test.js +2 -2
- package/hooks/use-day.js +5 -9
- package/hooks/use-day.test.js +5 -8
- package/hooks/use-decade.js +2 -1
- package/hooks/use-decade.test.js +21 -24
- package/hooks/use-month.js +2 -1
- package/hooks/use-month.test.js +81 -84
- package/hooks/use-year.js +2 -1
- package/hooks/use-year.test.js +27 -30
- package/package.json +1 -1
- package/utils/create-date-string.d.ts +1 -0
- package/utils/create-date-string.js +6 -0
- package/utils/dayjs-en.js +8 -1
- package/utils/get-current-year-month-and-date.test.js +10 -2
- package/utils/get-date-intervals.test.js +8 -11
- package/utils/get-date-invervals.js +3 -6
- package/utils/get-date-month-and-year.test.js +2 -2
- package/utils/get-days.js +2 -1
- package/utils/get-days.test.js +121 -124
- package/utils/get-each.js +1 -1
- package/utils/get-each.test.js +15 -15
- package/utils/get-initial-months.test.js +4 -4
- package/utils/get-months.js +2 -1
- package/utils/get-months.test.js +26 -29
- package/utils/get-next-active-month.test.js +13 -13
- package/utils/get-weekday-labels.test.js +6 -6
- package/utils/get-years.test.js +10 -13
|
@@ -4,7 +4,7 @@ const react_1 = require("@testing-library/react");
|
|
|
4
4
|
const react_2 = require("react");
|
|
5
5
|
const use_date_picker_1 = require("./use-date-picker");
|
|
6
6
|
test("base data", () => {
|
|
7
|
-
const BASE_DATE = new Date("2021-09-
|
|
7
|
+
const BASE_DATE = new Date("2021-09-15T00:00:00+02:00");
|
|
8
8
|
const { result } = (0, react_1.renderHook)(() => (0, use_date_picker_1.useDatePicker)({
|
|
9
9
|
selectedDate: BASE_DATE,
|
|
10
10
|
onDateChange: () => undefined,
|
|
@@ -15,7 +15,7 @@ test("base data", () => {
|
|
|
15
15
|
expect(result.current.hoveredDate).toBe(null);
|
|
16
16
|
expect(result.current.activeMonths).toStrictEqual([
|
|
17
17
|
{
|
|
18
|
-
date: new Date("2021-09-
|
|
18
|
+
date: new Date("2021-09-01T00:00:00+02:00"),
|
|
19
19
|
month: 8,
|
|
20
20
|
year: 2021,
|
|
21
21
|
},
|
|
@@ -19,8 +19,8 @@ test("base data", () => {
|
|
|
19
19
|
expect(result.current.focusedDate).toBe(null);
|
|
20
20
|
expect(result.current.hoveredDate).toBe(null);
|
|
21
21
|
expect(result.current.activeMonths).toStrictEqual([
|
|
22
|
-
{ date: new Date("2021-09-
|
|
23
|
-
{ date: new Date("2021-10-
|
|
22
|
+
{ date: new Date("2021-09-01T00:00:00+02:00"), month: 8, year: 2021 },
|
|
23
|
+
{ date: new Date("2021-10-01T00:00:00+02:00"), month: 9, year: 2021 },
|
|
24
24
|
]);
|
|
25
25
|
expect(result.current.isDateBlocked(new Date("2020-01-01"))).toBe(false);
|
|
26
26
|
expect(result.current.isDateBlocked(new Date("2019-12-31"))).toBe(true);
|
package/hooks/use-day.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useDay = useDay;
|
|
7
4
|
const empty_array_1 = require("@uxf/core/constants/empty-array");
|
|
8
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
5
|
const react_1 = require("react");
|
|
10
6
|
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
11
7
|
const get_date_invervals_1 = require("../utils/get-date-invervals");
|
|
@@ -46,12 +42,12 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
46
42
|
}, [date, onDateFocus]);
|
|
47
43
|
const dateIntervals = (0, get_date_invervals_1.getDateIntervals)(disabledDates);
|
|
48
44
|
const _isFirstUnavailableDate = () => {
|
|
49
|
-
return dateIntervals.some((interval) => (0,
|
|
45
|
+
return dateIntervals.some((interval) => (0, dayjs_en_1.dayjsEn)(interval.start).isSame(date, "day"));
|
|
50
46
|
};
|
|
51
47
|
const _isLastUnavailableDate = () => {
|
|
52
|
-
return dateIntervals.some((interval) => (0,
|
|
48
|
+
return dateIntervals.some((interval) => (0, dayjs_en_1.dayjsEn)(interval.end).isSame(date, "day"));
|
|
53
49
|
};
|
|
54
|
-
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.dates.some((configDay) => (0,
|
|
50
|
+
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.dates.some((configDay) => (0, dayjs_en_1.dayjsEn)(configDay).isSame(date, "day")));
|
|
55
51
|
const flags = applicableDatesConfigs === null || applicableDatesConfigs === void 0 ? void 0 : applicableDatesConfigs.reduce((acc, curr) => {
|
|
56
52
|
if (!curr.flag) {
|
|
57
53
|
return acc;
|
|
@@ -59,8 +55,8 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
59
55
|
const intervals = (0, get_date_invervals_1.getDateIntervals)(curr.dates);
|
|
60
56
|
acc.push({
|
|
61
57
|
flag: curr.flag,
|
|
62
|
-
isFirst: intervals.some((interval) => (0,
|
|
63
|
-
isLast: intervals.some((interval) => (0,
|
|
58
|
+
isFirst: intervals.some((interval) => (0, dayjs_en_1.dayjsEn)(interval.start).isSame(date, "day")),
|
|
59
|
+
isLast: intervals.some((interval) => (0, dayjs_en_1.dayjsEn)(interval.end).isSame(date, "day")),
|
|
64
60
|
});
|
|
65
61
|
return acc;
|
|
66
62
|
}, []);
|
package/hooks/use-day.test.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const react_1 = require("@testing-library/react");
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
4
|
const react_2 = require("react");
|
|
5
|
+
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
9
6
|
const use_day_1 = require("./use-day");
|
|
10
7
|
const e = { preventDefault: () => undefined, key: undefined };
|
|
11
8
|
beforeAll(() => {
|
|
@@ -100,10 +97,10 @@ test("actions", () => {
|
|
|
100
97
|
dayRef: ref.current,
|
|
101
98
|
focusedDate: null,
|
|
102
99
|
isDateBlocked: () => false,
|
|
103
|
-
isDateFocused: (date) => (0,
|
|
104
|
-
isDateHovered: (date) => (0,
|
|
105
|
-
isDateInsideRange: (date) => (0,
|
|
106
|
-
isDateSelected: (date) => (0,
|
|
100
|
+
isDateFocused: (date) => (0, dayjs_en_1.dayjsEn)(date).isSame(focusedDate, "day"),
|
|
101
|
+
isDateHovered: (date) => (0, dayjs_en_1.dayjsEn)(date).isSame(hoveredDate, "day"),
|
|
102
|
+
isDateInsideRange: (date) => (0, dayjs_en_1.dayjsEn)(date).isSame(insideRangeDate, "day"),
|
|
103
|
+
isDateSelected: (date) => (0, dayjs_en_1.dayjsEn)(date).isSame(selectedDate, "day"),
|
|
107
104
|
onDateFocus: (date) => (focusedDate = date),
|
|
108
105
|
onDateHover: (date) => (hoveredDate = date),
|
|
109
106
|
onDateSelect: (date) => (selectedDate = date),
|
package/hooks/use-decade.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.decadeLabelFormatFn = exports.yearLabelFormatFn = void 0;
|
|
4
4
|
exports.useDecade = useDecade;
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const create_date_string_1 = require("../utils/create-date-string");
|
|
6
7
|
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
7
8
|
const get_years_1 = require("../utils/get-years");
|
|
8
9
|
const yearLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("YYYY");
|
|
@@ -10,7 +11,7 @@ exports.yearLabelFormatFn = yearLabelFormatFn;
|
|
|
10
11
|
const decadeLabelFormatFn = (start, end) => `${(0, dayjs_en_1.dayjsEn)(start).format("YYYY")} \u2013 ${(0, dayjs_en_1.dayjsEn)(end).format("YYYY")}`;
|
|
11
12
|
exports.decadeLabelFormatFn = decadeLabelFormatFn;
|
|
12
13
|
function useDecade({ yearLabelFormat = exports.yearLabelFormatFn, decadeLabelFormat = exports.decadeLabelFormatFn, year, }) {
|
|
13
|
-
const currentYear = new Date(year, 0);
|
|
14
|
+
const currentYear = new Date((0, create_date_string_1.createDateString)(year, 0));
|
|
14
15
|
const startYear = (0, dayjs_en_1.dayjsEn)(currentYear).subtract(4, "years").startOf("year").toDate();
|
|
15
16
|
const endYear = (0, dayjs_en_1.dayjsEn)(currentYear).add(4, "years").endOf("year").toDate();
|
|
16
17
|
const years = (0, react_1.useMemo)(() => (0, get_years_1.getYears)({ startYear, endYear, yearLabelFormat }), [endYear, startYear, yearLabelFormat]);
|
package/hooks/use-decade.test.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const react_1 = require("@testing-library/react");
|
|
7
|
-
const
|
|
4
|
+
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
8
5
|
const use_decade_1 = require("./use-decade");
|
|
9
6
|
test("useDecade", () => {
|
|
10
7
|
const { result } = (0, react_1.renderHook)(() => (0, use_decade_1.useDecade)({
|
|
@@ -12,33 +9,33 @@ test("useDecade", () => {
|
|
|
12
9
|
}));
|
|
13
10
|
expect(result.current.decadeLabel).toBe("2017 – 2025");
|
|
14
11
|
expect(result.current.years).toStrictEqual([
|
|
15
|
-
{ date: new Date("2017-01-01"), yearLabel: "2017" },
|
|
16
|
-
{ date: new Date("2018-01-01"), yearLabel: "2018" },
|
|
17
|
-
{ date: new Date("2019-01-01"), yearLabel: "2019" },
|
|
18
|
-
{ date: new Date("2020-01-01"), yearLabel: "2020" },
|
|
19
|
-
{ date: new Date("2021-01-01"), yearLabel: "2021" },
|
|
20
|
-
{ date: new Date("2022-01-01"), yearLabel: "2022" },
|
|
21
|
-
{ date: new Date("2023-01-01"), yearLabel: "2023" },
|
|
22
|
-
{ date: new Date("2024-01-01"), yearLabel: "2024" },
|
|
23
|
-
{ date: new Date("2025-01-01"), yearLabel: "2025" },
|
|
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" },
|
|
24
21
|
]);
|
|
25
22
|
});
|
|
26
23
|
test("useDecade with custom formats", () => {
|
|
27
24
|
const { result } = (0, react_1.renderHook)(() => (0, use_decade_1.useDecade)({
|
|
28
25
|
year: 2021,
|
|
29
|
-
decadeLabelFormat: (start, end) => `${(0,
|
|
30
|
-
yearLabelFormat: (date) => (0,
|
|
26
|
+
decadeLabelFormat: (start, end) => `${(0, dayjs_en_1.dayjsEn)(start).format("YY")} - ${(0, dayjs_en_1.dayjsEn)(end).format("YY")}`,
|
|
27
|
+
yearLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("YY"),
|
|
31
28
|
}));
|
|
32
29
|
expect(result.current.decadeLabel).toBe("17 - 25");
|
|
33
30
|
expect(result.current.years).toStrictEqual([
|
|
34
|
-
{ date: new Date("2017-01-01"), yearLabel: "17" },
|
|
35
|
-
{ date: new Date("2018-01-01"), yearLabel: "18" },
|
|
36
|
-
{ date: new Date("2019-01-01"), yearLabel: "19" },
|
|
37
|
-
{ date: new Date("2020-01-01"), yearLabel: "20" },
|
|
38
|
-
{ date: new Date("2021-01-01"), yearLabel: "21" },
|
|
39
|
-
{ date: new Date("2022-01-01"), yearLabel: "22" },
|
|
40
|
-
{ date: new Date("2023-01-01"), yearLabel: "23" },
|
|
41
|
-
{ date: new Date("2024-01-01"), yearLabel: "24" },
|
|
42
|
-
{ date: new Date("2025-01-01"), yearLabel: "25" },
|
|
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" },
|
|
43
40
|
]);
|
|
44
41
|
});
|
package/hooks/use-month.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.monthLabelFormatFn = exports.weekdayLabelFormatFn = exports.dayLabelFormatFn = void 0;
|
|
4
4
|
exports.useMonth = useMonth;
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const create_date_string_1 = require("../utils/create-date-string");
|
|
6
7
|
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
7
8
|
const get_days_1 = require("../utils/get-days");
|
|
8
9
|
const get_weekday_labels_1 = require("../utils/get-weekday-labels");
|
|
@@ -17,7 +18,7 @@ function useMonth({ dayLabelFormat = exports.dayLabelFormatFn, firstDayOfWeek =
|
|
|
17
18
|
const weekdayLabels = (0, react_1.useMemo)(() => (0, get_weekday_labels_1.getWeekdayLabels)({ firstDayOfWeek, weekdayLabelFormat }), [firstDayOfWeek, weekdayLabelFormat]);
|
|
18
19
|
return {
|
|
19
20
|
days,
|
|
20
|
-
monthLabel: monthLabelFormat(new Date(year, month)),
|
|
21
|
+
monthLabel: monthLabelFormat(new Date((0, create_date_string_1.createDateString)(year, month))),
|
|
21
22
|
weekdayLabels,
|
|
22
23
|
};
|
|
23
24
|
}
|
package/hooks/use-month.test.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const react_1 = require("@testing-library/react");
|
|
7
|
-
const
|
|
4
|
+
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
8
5
|
const use_month_1 = require("./use-month");
|
|
9
6
|
test("useMonth", () => {
|
|
10
7
|
const { result } = (0, react_1.renderHook)(() => (0, use_month_1.useMonth)({
|
|
@@ -13,48 +10,48 @@ test("useMonth", () => {
|
|
|
13
10
|
}));
|
|
14
11
|
expect(result.current.monthLabel).toBe("January 2021");
|
|
15
12
|
expect(result.current.days).toStrictEqual([
|
|
16
|
-
{ dayLabel: "27", date: new Date("2020-12-
|
|
17
|
-
{ dayLabel: "28", date: new Date("2020-12-
|
|
18
|
-
{ dayLabel: "29", date: new Date("2020-12-
|
|
19
|
-
{ dayLabel: "30", date: new Date("2020-12-
|
|
20
|
-
{ dayLabel: "31", date: new Date("2020-12-
|
|
21
|
-
{ dayLabel: "01", date: new Date("2021-01-01"), currentMonth: true },
|
|
22
|
-
{ dayLabel: "02", date: new Date("2021-01-
|
|
23
|
-
{ dayLabel: "03", date: new Date("2021-01-
|
|
24
|
-
{ dayLabel: "04", date: new Date("2021-01-
|
|
25
|
-
{ dayLabel: "05", date: new Date("2021-01-
|
|
26
|
-
{ dayLabel: "06", date: new Date("2021-01-
|
|
27
|
-
{ dayLabel: "07", date: new Date("2021-01-
|
|
28
|
-
{ dayLabel: "08", date: new Date("2021-01-
|
|
29
|
-
{ dayLabel: "09", date: new Date("2021-01-
|
|
30
|
-
{ dayLabel: "10", date: new Date("2021-01-
|
|
31
|
-
{ dayLabel: "11", date: new Date("2021-01-
|
|
32
|
-
{ dayLabel: "12", date: new Date("2021-01-
|
|
33
|
-
{ dayLabel: "13", date: new Date("2021-01-
|
|
34
|
-
{ dayLabel: "14", date: new Date("2021-01-
|
|
35
|
-
{ dayLabel: "15", date: new Date("2021-01-
|
|
36
|
-
{ dayLabel: "16", date: new Date("2021-01-
|
|
37
|
-
{ dayLabel: "17", date: new Date("2021-01-
|
|
38
|
-
{ dayLabel: "18", date: new Date("2021-01-
|
|
39
|
-
{ dayLabel: "19", date: new Date("2021-01-
|
|
40
|
-
{ dayLabel: "20", date: new Date("2021-01-
|
|
41
|
-
{ dayLabel: "21", date: new Date("2021-01-
|
|
42
|
-
{ dayLabel: "22", date: new Date("2021-01-
|
|
43
|
-
{ dayLabel: "23", date: new Date("2021-01-
|
|
44
|
-
{ dayLabel: "24", date: new Date("2021-01-
|
|
45
|
-
{ dayLabel: "25", date: new Date("2021-01-
|
|
46
|
-
{ dayLabel: "26", date: new Date("2021-01-
|
|
47
|
-
{ dayLabel: "27", date: new Date("2021-01-
|
|
48
|
-
{ dayLabel: "28", date: new Date("2021-01-
|
|
49
|
-
{ dayLabel: "29", date: new Date("2021-01-
|
|
50
|
-
{ dayLabel: "30", date: new Date("2021-01-
|
|
51
|
-
{ dayLabel: "31", date: new Date("2021-01-
|
|
52
|
-
{ dayLabel: "01", date: new Date("2021-02-01"), currentMonth: false },
|
|
53
|
-
{ dayLabel: "02", date: new Date("2021-02-
|
|
54
|
-
{ dayLabel: "03", date: new Date("2021-02-
|
|
55
|
-
{ dayLabel: "04", date: new Date("2021-02-
|
|
56
|
-
{ dayLabel: "05", date: new Date("2021-02-
|
|
57
|
-
{ dayLabel: "06", date: new Date("2021-02-
|
|
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 },
|
|
58
55
|
]);
|
|
59
56
|
expect(result.current.weekdayLabels).toStrictEqual(["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]);
|
|
60
57
|
});
|
|
@@ -63,47 +60,47 @@ test("useMonth with custom formats and firstDayOfWeek", () => {
|
|
|
63
60
|
year: 2021,
|
|
64
61
|
month: 0,
|
|
65
62
|
firstDayOfWeek: 1,
|
|
66
|
-
monthLabelFormat: (date) => (0,
|
|
67
|
-
dayLabelFormat: (date) => (0,
|
|
68
|
-
weekdayLabelFormat: (date) => (0,
|
|
63
|
+
monthLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("MM"),
|
|
64
|
+
dayLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("D"),
|
|
65
|
+
weekdayLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("dddd"),
|
|
69
66
|
}));
|
|
70
67
|
expect(result.current.monthLabel).toBe("01");
|
|
71
68
|
expect(result.current.days).toStrictEqual([
|
|
72
|
-
{ dayLabel: "28", date: new Date("2020-12-
|
|
73
|
-
{ dayLabel: "29", date: new Date("2020-12-
|
|
74
|
-
{ dayLabel: "30", date: new Date("2020-12-
|
|
75
|
-
{ dayLabel: "31", date: new Date("2020-12-
|
|
76
|
-
{ dayLabel: "1", date: new Date("2021-01-01"), currentMonth: true },
|
|
77
|
-
{ dayLabel: "2", date: new Date("2021-01-
|
|
78
|
-
{ dayLabel: "3", date: new Date("2021-01-
|
|
79
|
-
{ dayLabel: "4", date: new Date("2021-01-
|
|
80
|
-
{ dayLabel: "5", date: new Date("2021-01-
|
|
81
|
-
{ dayLabel: "6", date: new Date("2021-01-
|
|
82
|
-
{ dayLabel: "7", date: new Date("2021-01-
|
|
83
|
-
{ dayLabel: "8", date: new Date("2021-01-
|
|
84
|
-
{ dayLabel: "9", date: new Date("2021-01-
|
|
85
|
-
{ dayLabel: "10", date: new Date("2021-01-
|
|
86
|
-
{ dayLabel: "11", date: new Date("2021-01-
|
|
87
|
-
{ dayLabel: "12", date: new Date("2021-01-
|
|
88
|
-
{ dayLabel: "13", date: new Date("2021-01-
|
|
89
|
-
{ dayLabel: "14", date: new Date("2021-01-
|
|
90
|
-
{ dayLabel: "15", date: new Date("2021-01-
|
|
91
|
-
{ dayLabel: "16", date: new Date("2021-01-
|
|
92
|
-
{ dayLabel: "17", date: new Date("2021-01-
|
|
93
|
-
{ dayLabel: "18", date: new Date("2021-01-
|
|
94
|
-
{ dayLabel: "19", date: new Date("2021-01-
|
|
95
|
-
{ dayLabel: "20", date: new Date("2021-01-
|
|
96
|
-
{ dayLabel: "21", date: new Date("2021-01-
|
|
97
|
-
{ dayLabel: "22", date: new Date("2021-01-
|
|
98
|
-
{ dayLabel: "23", date: new Date("2021-01-
|
|
99
|
-
{ dayLabel: "24", date: new Date("2021-01-
|
|
100
|
-
{ dayLabel: "25", date: new Date("2021-01-
|
|
101
|
-
{ dayLabel: "26", date: new Date("2021-01-
|
|
102
|
-
{ dayLabel: "27", date: new Date("2021-01-
|
|
103
|
-
{ dayLabel: "28", date: new Date("2021-01-
|
|
104
|
-
{ dayLabel: "29", date: new Date("2021-01-
|
|
105
|
-
{ dayLabel: "30", date: new Date("2021-01-
|
|
106
|
-
{ dayLabel: "31", date: new Date("2021-01-
|
|
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 },
|
|
107
104
|
]);
|
|
108
105
|
expect(result.current.weekdayLabels).toStrictEqual([
|
|
109
106
|
"Monday",
|
package/hooks/use-year.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.yearLabelFormatFn = exports.monthLabelFormatFn = void 0;
|
|
4
4
|
exports.useYear = useYear;
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const create_date_string_1 = require("../utils/create-date-string");
|
|
6
7
|
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
7
8
|
const get_months_1 = require("../utils/get-months");
|
|
8
9
|
const monthLabelFormatFn = (date) => (0, dayjs_en_1.dayjsEn)(date).format("MMMM"); // localized
|
|
@@ -13,6 +14,6 @@ function useYear({ yearLabelFormat = exports.yearLabelFormatFn, monthLabelFormat
|
|
|
13
14
|
const months = (0, react_1.useMemo)(() => (0, get_months_1.getMonths)({ year, monthLabelFormat }), [year, monthLabelFormat]);
|
|
14
15
|
return {
|
|
15
16
|
months,
|
|
16
|
-
yearLabel: yearLabelFormat(new Date(year, 0)),
|
|
17
|
+
yearLabel: yearLabelFormat(new Date((0, create_date_string_1.createDateString)(year, 0))),
|
|
17
18
|
};
|
|
18
19
|
}
|
package/hooks/use-year.test.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const react_1 = require("@testing-library/react");
|
|
7
|
-
const
|
|
4
|
+
const dayjs_en_1 = require("../utils/dayjs-en");
|
|
8
5
|
const use_year_1 = require("./use-year");
|
|
9
6
|
test("useYear", () => {
|
|
10
7
|
const { result } = (0, react_1.renderHook)(() => (0, use_year_1.useYear)({
|
|
@@ -12,39 +9,39 @@ test("useYear", () => {
|
|
|
12
9
|
}));
|
|
13
10
|
expect(result.current.yearLabel).toBe("2021");
|
|
14
11
|
expect(result.current.months).toStrictEqual([
|
|
15
|
-
{ date: new Date("2021-01-01"), monthLabel: "January" },
|
|
16
|
-
{ date: new Date("2021-02-01"), monthLabel: "February" },
|
|
17
|
-
{ date: new Date("2021-03-01"), monthLabel: "March" },
|
|
18
|
-
{ date: new Date("2021-04-
|
|
19
|
-
{ date: new Date("2021-05-
|
|
20
|
-
{ date: new Date("2021-06-
|
|
21
|
-
{ date: new Date("2021-07-
|
|
22
|
-
{ date: new Date("2021-08-
|
|
23
|
-
{ date: new Date("2021-09-
|
|
24
|
-
{ date: new Date("2021-10-
|
|
25
|
-
{ date: new Date("2021-11-01"), monthLabel: "November" },
|
|
26
|
-
{ date: new Date("2021-12-01"), monthLabel: "December" },
|
|
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" },
|
|
27
24
|
]);
|
|
28
25
|
});
|
|
29
26
|
test("useYear with custom formats", () => {
|
|
30
27
|
const { result } = (0, react_1.renderHook)(() => (0, use_year_1.useYear)({
|
|
31
28
|
year: 2021,
|
|
32
|
-
monthLabelFormat: (date) => (0,
|
|
33
|
-
yearLabelFormat: (date) => (0,
|
|
29
|
+
monthLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("MM"),
|
|
30
|
+
yearLabelFormat: (date) => (0, dayjs_en_1.dayjsEn)(date).format("YY"),
|
|
34
31
|
}));
|
|
35
32
|
expect(result.current.yearLabel).toBe("21");
|
|
36
33
|
expect(result.current.months).toStrictEqual([
|
|
37
|
-
{ date: new Date("2021-01-01"), monthLabel: "01" },
|
|
38
|
-
{ date: new Date("2021-02-01"), monthLabel: "02" },
|
|
39
|
-
{ date: new Date("2021-03-01"), monthLabel: "03" },
|
|
40
|
-
{ date: new Date("2021-04-
|
|
41
|
-
{ date: new Date("2021-05-
|
|
42
|
-
{ date: new Date("2021-06-
|
|
43
|
-
{ date: new Date("2021-07-
|
|
44
|
-
{ date: new Date("2021-08-
|
|
45
|
-
{ date: new Date("2021-09-
|
|
46
|
-
{ date: new Date("2021-10-
|
|
47
|
-
{ date: new Date("2021-11-01"), monthLabel: "11" },
|
|
48
|
-
{ date: new Date("2021-12-01"), monthLabel: "12" },
|
|
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" },
|
|
49
46
|
]);
|
|
50
47
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createDateString(year: number, month?: number, day?: number): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDateString = createDateString;
|
|
4
|
+
function createDateString(year, month, day) {
|
|
5
|
+
return `${year}-${((month !== null && month !== void 0 ? month : 0) + 1).toString().padStart(2, "0")}-${(day !== null && day !== void 0 ? day : 1).toString().padStart(2, "0")}`;
|
|
6
|
+
}
|
package/utils/dayjs-en.js
CHANGED
|
@@ -40,6 +40,13 @@ exports.dayjsEn = 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"));
|
|
43
|
+
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
44
|
+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
43
45
|
(0, dayjs_1.extend)(isBetween_1.default);
|
|
44
|
-
|
|
46
|
+
(0, dayjs_1.extend)(timezone_1.default);
|
|
47
|
+
(0, dayjs_1.extend)(utc_1.default);
|
|
48
|
+
const DEFAULT_TIMEZONE = "Europe/Prague";
|
|
49
|
+
const dayjsEn = (value) => {
|
|
50
|
+
return dayjs_1.default.tz(value, DEFAULT_TIMEZONE).locale("en");
|
|
51
|
+
};
|
|
45
52
|
exports.dayjsEn = dayjsEn;
|
|
@@ -6,7 +6,15 @@ beforeAll(() => {
|
|
|
6
6
|
});
|
|
7
7
|
test("getCurrentYearMonthAndDate", () => {
|
|
8
8
|
jest.setSystemTime(new Date("2021-08-10"));
|
|
9
|
-
expect((0, get_current_year_month_and_date_1.getCurrentYearMonthAndDate)()).toStrictEqual({
|
|
9
|
+
expect((0, get_current_year_month_and_date_1.getCurrentYearMonthAndDate)()).toStrictEqual({
|
|
10
|
+
year: 2021,
|
|
11
|
+
month: 7,
|
|
12
|
+
date: new Date("2021-08-01T00:00:00+02:00"),
|
|
13
|
+
});
|
|
10
14
|
jest.setSystemTime(new Date("2020-02-15"));
|
|
11
|
-
expect((0, get_current_year_month_and_date_1.getCurrentYearMonthAndDate)()).toStrictEqual({
|
|
15
|
+
expect((0, get_current_year_month_and_date_1.getCurrentYearMonthAndDate)()).toStrictEqual({
|
|
16
|
+
year: 2020,
|
|
17
|
+
month: 1,
|
|
18
|
+
date: new Date("2020-02-01T00:00:00+01:00"),
|
|
19
|
+
});
|
|
12
20
|
});
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
3
|
+
const dayjs_en_1 = require("./dayjs-en");
|
|
7
4
|
const get_date_invervals_1 = require("./get-date-invervals");
|
|
8
5
|
describe("getDateIntervals", () => {
|
|
9
6
|
it("should return empty array for empty input", () => {
|
|
10
7
|
expect((0, get_date_invervals_1.getDateIntervals)([])).toStrictEqual([]);
|
|
11
8
|
});
|
|
12
9
|
it("should return single date as an interval", () => {
|
|
13
|
-
const date = (0,
|
|
10
|
+
const date = (0, dayjs_en_1.dayjsEn)("2023-10-12").toDate();
|
|
14
11
|
expect((0, get_date_invervals_1.getDateIntervals)([date])).toStrictEqual([{ start: date, end: date }]);
|
|
15
12
|
});
|
|
16
13
|
it("should group contiguous dates into intervals", () => {
|
|
17
14
|
const dates = [
|
|
18
|
-
(0,
|
|
19
|
-
(0,
|
|
20
|
-
(0,
|
|
21
|
-
(0,
|
|
22
|
-
(0,
|
|
15
|
+
(0, dayjs_en_1.dayjsEn)("2023-10-12").toDate(),
|
|
16
|
+
(0, dayjs_en_1.dayjsEn)("2023-10-13").toDate(),
|
|
17
|
+
(0, dayjs_en_1.dayjsEn)("2023-10-14").toDate(),
|
|
18
|
+
(0, dayjs_en_1.dayjsEn)("2023-10-16").toDate(),
|
|
19
|
+
(0, dayjs_en_1.dayjsEn)("2023-10-17").toDate(),
|
|
23
20
|
];
|
|
24
21
|
const expected = [
|
|
25
22
|
{ start: dates.at(0), end: dates.at(2) },
|
|
@@ -28,7 +25,7 @@ describe("getDateIntervals", () => {
|
|
|
28
25
|
expect((0, get_date_invervals_1.getDateIntervals)(dates)).toStrictEqual(expected);
|
|
29
26
|
});
|
|
30
27
|
it("should handle non-contiguous dates", () => {
|
|
31
|
-
const dates = [(0,
|
|
28
|
+
const dates = [(0, dayjs_en_1.dayjsEn)("2023-10-12").toDate(), (0, dayjs_en_1.dayjsEn)("2023-10-14").toDate(), (0, dayjs_en_1.dayjsEn)("2023-10-16").toDate()];
|
|
32
29
|
const expected = [
|
|
33
30
|
{ start: dates.at(0), end: dates.at(0) },
|
|
34
31
|
{ start: dates.at(1), end: dates.at(1) },
|