@uxf/datepicker 16.15.0 → 16.16.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/contexts/date-picker-context.d.ts +1 -1
- package/contexts/date-picker-context.js +2 -2
- package/contexts/date-range-picker-context.d.ts +1 -1
- package/contexts/date-range-picker-context.js +2 -2
- package/contexts/time-picker-context.js +2 -2
- package/hooks/use-date-picker-navigation.d.ts +2 -2
- package/hooks/use-date-picker-navigation.js +22 -22
- package/hooks/use-date-picker-navigation.test.js +7 -7
- package/hooks/use-date-picker.d.ts +2 -2
- package/hooks/use-date-picker.js +32 -32
- package/hooks/use-date-picker.test.js +7 -7
- package/hooks/use-date-range-picker.d.ts +2 -2
- package/hooks/use-date-range-picker.js +62 -62
- package/hooks/use-date-range-picker.test.js +16 -16
- package/hooks/use-day.d.ts +1 -1
- package/hooks/use-day.js +22 -22
- package/hooks/use-day.test.js +12 -12
- package/hooks/use-decade.d.ts +1 -1
- package/hooks/use-decade.js +8 -8
- package/hooks/use-decade.test.js +6 -6
- package/hooks/use-hour.test.js +3 -3
- package/hooks/use-hours.test.js +3 -3
- package/hooks/use-minute.test.js +3 -3
- package/hooks/use-minutes.test.js +3 -3
- package/hooks/use-month.d.ts +2 -2
- package/hooks/use-month.js +10 -10
- package/hooks/use-month.test.js +7 -7
- package/hooks/use-time-picker.test.js +5 -5
- package/hooks/use-year.d.ts +1 -1
- package/hooks/use-year.js +7 -7
- package/hooks/use-year.test.js +6 -6
- package/package.json +5 -5
- package/utils/can-select-range.d.ts +1 -1
- package/utils/can-select-range.js +8 -8
- package/utils/can-select-range.test.js +10 -10
- package/utils/date-string.d.ts +1 -1
- package/utils/date-string.js +6 -6
- package/utils/date-string.test.js +33 -33
- package/utils/dayjs-utils.d.ts +1 -1
- package/utils/dayjs-utils.js +8 -41
- package/utils/dst-robustness.test.js +74 -74
- package/utils/get-current-year-month-and-date.d.ts +1 -1
- package/utils/get-current-year-month-and-date.js +2 -2
- package/utils/get-current-year-month-and-date.test.js +3 -3
- package/utils/get-date-intervals.test.js +15 -15
- package/utils/get-date-invervals.js +4 -4
- package/utils/get-date-month-and-year.d.ts +1 -1
- package/utils/get-date-month-and-year.js +4 -4
- package/utils/get-date-month-and-year.test.js +3 -3
- package/utils/get-days.d.ts +1 -1
- package/utils/get-days.js +17 -17
- package/utils/get-days.test.js +5 -5
- package/utils/get-each.d.ts +1 -1
- package/utils/get-each.js +5 -5
- package/utils/get-each.test.js +11 -11
- package/utils/get-first-active-month.d.ts +1 -1
- package/utils/get-first-active-month.js +2 -2
- package/utils/get-first-active-month.test.js +5 -5
- package/utils/get-initial-months.d.ts +1 -1
- package/utils/get-initial-months.js +6 -6
- package/utils/get-initial-months.test.js +5 -5
- package/utils/get-months.js +9 -9
- package/utils/get-months.test.js +4 -4
- package/utils/get-next-active-month.d.ts +1 -1
- package/utils/get-next-active-month.js +6 -6
- package/utils/get-next-active-month.test.js +9 -9
- package/utils/get-weekday-labels.d.ts +1 -1
- package/utils/get-weekday-labels.js +6 -6
- package/utils/get-weekday-labels.test.d.ts +1 -1
- package/utils/get-weekday-labels.test.js +8 -8
- package/utils/get-years.js +6 -6
- package/utils/get-years.test.js +5 -5
- package/utils/is-date-blocked.d.ts +1 -1
- package/utils/is-date-blocked.js +5 -5
- package/utils/is-date-blocked.test.js +16 -16
- package/utils/is-date-hovered.d.ts +1 -1
- package/utils/is-date-hovered.js +7 -7
- package/utils/is-date-hovered.test.js +9 -9
- package/utils/is-date-inside-range.d.ts +1 -1
- package/utils/is-date-selected.test.js +13 -13
- package/utils/is-end-date.d.ts +1 -1
- package/utils/is-end-date.test.js +10 -10
- package/utils/is-first-or-last-selected-date.d.ts +1 -1
- package/utils/is-first-or-last-selected-date.test.js +10 -10
- package/utils/is-in-unavailable-dates.d.ts +1 -1
- package/utils/is-in-unavailable-dates.test.js +9 -9
- package/utils/is-start-date.d.ts +1 -1
- package/utils/is-start-date.test.js +10 -10
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const dayjs_utils_ts_1 = require("./dayjs-utils.js");
|
|
4
|
+
const get_date_invervals_ts_1 = require("./get-date-invervals.js");
|
|
5
5
|
describe("getDateIntervals", () => {
|
|
6
6
|
it("should return empty array for empty input", () => {
|
|
7
|
-
expect((0,
|
|
7
|
+
expect((0, get_date_invervals_ts_1.getDateIntervals)([])).toStrictEqual([]);
|
|
8
8
|
});
|
|
9
9
|
it("should return single date as an interval", () => {
|
|
10
|
-
const date = (0,
|
|
11
|
-
expect((0,
|
|
10
|
+
const date = (0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-12").toDate();
|
|
11
|
+
expect((0, get_date_invervals_ts_1.getDateIntervals)([date])).toStrictEqual([{ start: date, end: date }]);
|
|
12
12
|
});
|
|
13
13
|
it("should group contiguous dates into intervals", () => {
|
|
14
14
|
const dates = [
|
|
15
|
-
(0,
|
|
16
|
-
(0,
|
|
17
|
-
(0,
|
|
18
|
-
(0,
|
|
19
|
-
(0,
|
|
15
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-12").toDate(),
|
|
16
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-13").toDate(),
|
|
17
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-14").toDate(),
|
|
18
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-16").toDate(),
|
|
19
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-17").toDate(),
|
|
20
20
|
];
|
|
21
21
|
const expected = [
|
|
22
22
|
{ start: dates.at(0), end: dates.at(2) },
|
|
23
23
|
{ start: dates.at(3), end: dates.at(4) },
|
|
24
24
|
];
|
|
25
|
-
expect((0,
|
|
25
|
+
expect((0, get_date_invervals_ts_1.getDateIntervals)(dates)).toStrictEqual(expected);
|
|
26
26
|
});
|
|
27
27
|
it("should handle non-contiguous dates", () => {
|
|
28
28
|
const dates = [
|
|
29
|
-
(0,
|
|
30
|
-
(0,
|
|
31
|
-
(0,
|
|
29
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-12").toDate(),
|
|
30
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-14").toDate(),
|
|
31
|
+
(0, dayjs_utils_ts_1.dayjsEnWithTz)("2023-10-16").toDate(),
|
|
32
32
|
];
|
|
33
33
|
const expected = [
|
|
34
34
|
{ start: dates.at(0), end: dates.at(0) },
|
|
35
35
|
{ start: dates.at(1), end: dates.at(1) },
|
|
36
36
|
{ start: dates.at(2), end: dates.at(2) },
|
|
37
37
|
];
|
|
38
|
-
expect((0,
|
|
38
|
+
expect((0, get_date_invervals_ts_1.getDateIntervals)(dates)).toStrictEqual(expected);
|
|
39
39
|
});
|
|
40
40
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDateIntervals = getDateIntervals;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const is_not_nil_js_1 = require("@uxf/core/utils/is-not-nil.js");
|
|
5
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
6
6
|
function getDateIntervals(dates) {
|
|
7
7
|
const sortedDates = dates.slice().sort((a, b) => a.getTime() - b.getTime());
|
|
8
8
|
const intervals = [];
|
|
@@ -11,7 +11,7 @@ function getDateIntervals(dates) {
|
|
|
11
11
|
let currentEnd = firstSortedDate !== null && firstSortedDate !== void 0 ? firstSortedDate : new Date();
|
|
12
12
|
for (let i = 1; i < sortedDates.length; i++) {
|
|
13
13
|
const currentDate = sortedDates[i];
|
|
14
|
-
if ((0,
|
|
14
|
+
if ((0, date_string_ts_1.toDateString)(currentDate) === (0, date_string_ts_1.addDays)((0, date_string_ts_1.toDateString)(currentEnd), 1)) {
|
|
15
15
|
currentEnd = currentDate;
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
@@ -20,7 +20,7 @@ function getDateIntervals(dates) {
|
|
|
20
20
|
currentEnd = currentDate;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
if ((0,
|
|
23
|
+
if ((0, is_not_nil_js_1.isNotNil)(firstSortedDate)) {
|
|
24
24
|
intervals.push({ start: currentStart, end: currentEnd });
|
|
25
25
|
}
|
|
26
26
|
return intervals;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MonthType } from "./types";
|
|
1
|
+
import { MonthType } from "./types.ts";
|
|
2
2
|
export declare function getDateMonthAndYear(date: Date): MonthType;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDateMonthAndYear = getDateMonthAndYear;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const create_date_string_ts_1 = require("./create-date-string.js");
|
|
5
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
6
6
|
function getDateMonthAndYear(date) {
|
|
7
|
-
const ds = (0,
|
|
7
|
+
const ds = (0, date_string_ts_1.toDateString)(date);
|
|
8
8
|
const year = parseInt(ds.slice(0, 4), 10);
|
|
9
9
|
const month = parseInt(ds.slice(5, 7), 10) - 1; // 0-indexed, matching dayjs convention
|
|
10
10
|
return {
|
|
11
11
|
year,
|
|
12
12
|
month,
|
|
13
|
-
date: (0,
|
|
13
|
+
date: (0, date_string_ts_1.fromDateString)((0, create_date_string_ts_1.createDateString)(year, month)),
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const get_date_month_and_year_ts_1 = require("./get-date-month-and-year.js");
|
|
4
4
|
test("getDateMonthAndYear", () => {
|
|
5
|
-
expect((0,
|
|
5
|
+
expect((0, get_date_month_and_year_ts_1.getDateMonthAndYear)(new Date("2021-08-10"))).toStrictEqual({
|
|
6
6
|
year: 2021,
|
|
7
7
|
month: 7,
|
|
8
8
|
date: new Date("2021-08-01T00:00:00Z"),
|
|
9
9
|
});
|
|
10
|
-
expect((0,
|
|
10
|
+
expect((0, get_date_month_and_year_ts_1.getDateMonthAndYear)(new Date("2020-02-15"))).toStrictEqual({
|
|
11
11
|
year: 2020,
|
|
12
12
|
month: 1,
|
|
13
13
|
date: new Date("2020-02-01T00:00:00Z"),
|
package/utils/get-days.d.ts
CHANGED
package/utils/get-days.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDays = getDays;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
function getDays({ year, month, firstDayOfWeek = 0, dayLabelFormat = (date) => (0,
|
|
9
|
-
const date = new Date((0,
|
|
4
|
+
const create_date_string_ts_1 = require("./create-date-string.js");
|
|
5
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
6
|
+
const dayjs_utils_ts_1 = require("./dayjs-utils.js");
|
|
7
|
+
const get_each_ts_1 = require("./get-each.js");
|
|
8
|
+
function getDays({ year, month, firstDayOfWeek = 0, dayLabelFormat = (date) => (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).format("DD"), }) {
|
|
9
|
+
const date = new Date((0, create_date_string_ts_1.createDateString)(year, month));
|
|
10
10
|
const lastDayOfWeek = firstDayOfWeek + 7;
|
|
11
|
-
const monthStart = (0,
|
|
11
|
+
const monthStart = (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).startOf("month");
|
|
12
12
|
const monthStartStr = monthStart.format("YYYY-MM-DD");
|
|
13
13
|
const monthStartDay = monthStart.day();
|
|
14
|
-
const monthEnd = (0,
|
|
14
|
+
const monthEnd = (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).endOf("month");
|
|
15
15
|
const monthEndStr = monthEnd.format("YYYY-MM-DD");
|
|
16
16
|
const monthEndDay = monthEnd.day();
|
|
17
17
|
const prevMonthDaysCount = monthStartDay >= firstDayOfWeek ? monthStartDay - firstDayOfWeek : 6 - firstDayOfWeek + monthStartDay + 1;
|
|
18
18
|
const prevMonthDays = prevMonthDaysCount > 0
|
|
19
|
-
? (0,
|
|
19
|
+
? (0, get_each_ts_1.getEach)((0, date_string_ts_1.addDays)(monthStartStr, -prevMonthDaysCount), (0, date_string_ts_1.addDays)(monthStartStr, -1), "day").map((d) => ({
|
|
20
20
|
currentMonth: false,
|
|
21
|
-
date: (0,
|
|
22
|
-
dayLabel: dayLabelFormat((0,
|
|
21
|
+
date: (0, date_string_ts_1.fromDateString)(d),
|
|
22
|
+
dayLabel: dayLabelFormat((0, date_string_ts_1.fromDateString)(d)),
|
|
23
23
|
}))
|
|
24
24
|
: [];
|
|
25
25
|
const nextMonthDaysCount = lastDayOfWeek - monthEndDay - 1;
|
|
26
26
|
const nextMonthDays = nextMonthDaysCount > 0 && nextMonthDaysCount < 7
|
|
27
|
-
? (0,
|
|
27
|
+
? (0, get_each_ts_1.getEach)((0, date_string_ts_1.addDays)(monthEndStr, 1), (0, date_string_ts_1.addDays)(monthEndStr, nextMonthDaysCount), "day").map((d) => ({
|
|
28
28
|
currentMonth: false,
|
|
29
|
-
date: (0,
|
|
30
|
-
dayLabel: dayLabelFormat((0,
|
|
29
|
+
date: (0, date_string_ts_1.fromDateString)(d),
|
|
30
|
+
dayLabel: dayLabelFormat((0, date_string_ts_1.fromDateString)(d)),
|
|
31
31
|
}))
|
|
32
32
|
: [];
|
|
33
|
-
const days = (0,
|
|
33
|
+
const days = (0, get_each_ts_1.getEach)(monthStartStr, monthEndStr, "day").map((d) => ({
|
|
34
34
|
currentMonth: true,
|
|
35
|
-
date: (0,
|
|
36
|
-
dayLabel: dayLabelFormat((0,
|
|
35
|
+
date: (0, date_string_ts_1.fromDateString)(d),
|
|
36
|
+
dayLabel: dayLabelFormat((0, date_string_ts_1.fromDateString)(d)),
|
|
37
37
|
}));
|
|
38
38
|
return [...prevMonthDays, ...days, ...nextMonthDays];
|
|
39
39
|
}
|
package/utils/get-days.test.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const dayjs_utils_ts_1 = require("./dayjs-utils.js");
|
|
4
|
+
const get_days_ts_1 = require("./get-days.js");
|
|
5
5
|
test("getDays", () => {
|
|
6
|
-
expect((0,
|
|
6
|
+
expect((0, get_days_ts_1.getDays)({ year: 2021, month: 0 })).toStrictEqual([
|
|
7
7
|
{ dayLabel: "27", date: new Date("2020-12-27T00:00:00Z"), currentMonth: false },
|
|
8
8
|
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00Z"), currentMonth: false },
|
|
9
9
|
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00Z"), currentMonth: false },
|
|
@@ -49,7 +49,7 @@ test("getDays", () => {
|
|
|
49
49
|
]);
|
|
50
50
|
});
|
|
51
51
|
test("getDays with custom format", () => {
|
|
52
|
-
expect((0,
|
|
52
|
+
expect((0, get_days_ts_1.getDays)({ year: 2021, month: 0, dayLabelFormat: (date) => (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).format("D") })).toStrictEqual([
|
|
53
53
|
{ dayLabel: "27", date: new Date("2020-12-27T00:00:00Z"), currentMonth: false },
|
|
54
54
|
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00Z"), currentMonth: false },
|
|
55
55
|
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00Z"), currentMonth: false },
|
|
@@ -95,7 +95,7 @@ test("getDays with custom format", () => {
|
|
|
95
95
|
]);
|
|
96
96
|
});
|
|
97
97
|
test("getDays with custom firstDayOfWeek", () => {
|
|
98
|
-
expect((0,
|
|
98
|
+
expect((0, get_days_ts_1.getDays)({ year: 2021, month: 0, firstDayOfWeek: 1 })).toStrictEqual([
|
|
99
99
|
{ dayLabel: "28", date: new Date("2020-12-28T00:00:00Z"), currentMonth: false },
|
|
100
100
|
{ dayLabel: "29", date: new Date("2020-12-29T00:00:00Z"), currentMonth: false },
|
|
101
101
|
{ dayLabel: "30", date: new Date("2020-12-30T00:00:00Z"), currentMonth: false },
|
package/utils/get-each.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DateString } from "@uxf/core/date";
|
|
1
|
+
import { DateString } from "@uxf/core/date/index.js";
|
|
2
2
|
export declare function getEach(start: DateString, end: DateString, type: "day" | "month" | "year"): DateString[];
|
package/utils/get-each.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEach = getEach;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const create_date_string_ts_1 = require("./create-date-string.js");
|
|
5
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
6
6
|
const DAY_MS = 86400000;
|
|
7
7
|
function getEach(start, end, type) {
|
|
8
8
|
if (type === "day") {
|
|
@@ -14,7 +14,7 @@ function getEach(start, end, type) {
|
|
|
14
14
|
const count = Math.round((endMs - startMs) / DAY_MS) + 1;
|
|
15
15
|
const results = new Array(count);
|
|
16
16
|
for (let i = 0; i < count; i++) {
|
|
17
|
-
results[i] = (0,
|
|
17
|
+
results[i] = (0, date_string_ts_1.toDateString)(new Date(startMs + i * DAY_MS));
|
|
18
18
|
}
|
|
19
19
|
return results;
|
|
20
20
|
}
|
|
@@ -28,7 +28,7 @@ function getEach(start, end, type) {
|
|
|
28
28
|
const results = new Array(count);
|
|
29
29
|
for (let i = 0; i < count; i++) {
|
|
30
30
|
const totalMonths = sm - 1 + i; // 0-indexed from start month
|
|
31
|
-
results[i] = (0,
|
|
31
|
+
results[i] = (0, create_date_string_ts_1.createDateString)(sy + Math.floor(totalMonths / 12), totalMonths % 12);
|
|
32
32
|
}
|
|
33
33
|
return results;
|
|
34
34
|
}
|
|
@@ -40,7 +40,7 @@ function getEach(start, end, type) {
|
|
|
40
40
|
}
|
|
41
41
|
const results = new Array(ey - sy + 1);
|
|
42
42
|
for (let i = 0; i < results.length; i++) {
|
|
43
|
-
results[i] = (0,
|
|
43
|
+
results[i] = (0, create_date_string_ts_1.createDateString)(sy + i);
|
|
44
44
|
}
|
|
45
45
|
return results;
|
|
46
46
|
}
|
package/utils/get-each.test.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const get_each_ts_1 = require("./get-each.js");
|
|
4
4
|
test("getEach day", () => {
|
|
5
|
-
expect((0,
|
|
5
|
+
expect((0, get_each_ts_1.getEach)("2021-05-05", "2021-05-07", "day")).toStrictEqual(["2021-05-05", "2021-05-06", "2021-05-07"]);
|
|
6
6
|
});
|
|
7
7
|
test("getEach day — DST fall-back (Oct 25 2026)", () => {
|
|
8
|
-
expect((0,
|
|
8
|
+
expect((0, get_each_ts_1.getEach)("2026-10-24", "2026-10-26", "day")).toStrictEqual(["2026-10-24", "2026-10-25", "2026-10-26"]);
|
|
9
9
|
});
|
|
10
10
|
test("getEach day — DST spring-forward (Mar 29 2026)", () => {
|
|
11
|
-
expect((0,
|
|
11
|
+
expect((0, get_each_ts_1.getEach)("2026-03-28", "2026-03-30", "day")).toStrictEqual(["2026-03-28", "2026-03-29", "2026-03-30"]);
|
|
12
12
|
});
|
|
13
13
|
test("getEach month", () => {
|
|
14
|
-
expect((0,
|
|
14
|
+
expect((0, get_each_ts_1.getEach)("2021-05-05", "2021-08-07", "month")).toStrictEqual([
|
|
15
15
|
"2021-05-01",
|
|
16
16
|
"2021-06-01",
|
|
17
17
|
"2021-07-01",
|
|
@@ -19,7 +19,7 @@ test("getEach month", () => {
|
|
|
19
19
|
]);
|
|
20
20
|
});
|
|
21
21
|
test("getEach month — year boundary", () => {
|
|
22
|
-
expect((0,
|
|
22
|
+
expect((0, get_each_ts_1.getEach)("2021-11-01", "2022-02-01", "month")).toStrictEqual([
|
|
23
23
|
"2021-11-01",
|
|
24
24
|
"2021-12-01",
|
|
25
25
|
"2022-01-01",
|
|
@@ -27,7 +27,7 @@ test("getEach month — year boundary", () => {
|
|
|
27
27
|
]);
|
|
28
28
|
});
|
|
29
29
|
test("getEach year", () => {
|
|
30
|
-
expect((0,
|
|
30
|
+
expect((0, get_each_ts_1.getEach)("2015-05-05", "2020-05-07", "year")).toStrictEqual([
|
|
31
31
|
"2015-01-01",
|
|
32
32
|
"2016-01-01",
|
|
33
33
|
"2017-01-01",
|
|
@@ -37,10 +37,10 @@ test("getEach year", () => {
|
|
|
37
37
|
]);
|
|
38
38
|
});
|
|
39
39
|
test("getEach single day", () => {
|
|
40
|
-
expect((0,
|
|
40
|
+
expect((0, get_each_ts_1.getEach)("2021-05-05", "2021-05-05", "day")).toStrictEqual(["2021-05-05"]);
|
|
41
41
|
});
|
|
42
42
|
test("getEach invalid input throws", () => {
|
|
43
|
-
expect(() => (0,
|
|
44
|
-
expect(() => (0,
|
|
45
|
-
expect(() => (0,
|
|
43
|
+
expect(() => (0, get_each_ts_1.getEach)("2015-05-05", "2014-05-07", "day")).toThrow("start must precede end");
|
|
44
|
+
expect(() => (0, get_each_ts_1.getEach)("2021-06-01", "2021-05-01", "month")).toThrow("start must precede end");
|
|
45
|
+
expect(() => (0, get_each_ts_1.getEach)("2020-01-01", "2019-01-01", "year")).toThrow("start must precede end");
|
|
46
46
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MonthType } from "./types";
|
|
1
|
+
import { MonthType } from "./types.ts";
|
|
2
2
|
/**
|
|
3
3
|
* The first month a date picker shows. `activeMonths` always holds at least one month (`getInitialMonths` starts with
|
|
4
4
|
* one and navigation keeps the count), so the current month is never returned in practice: it only satisfies the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFirstActiveMonth = getFirstActiveMonth;
|
|
4
|
-
const
|
|
4
|
+
const get_current_year_month_and_date_ts_1 = require("./get-current-year-month-and-date.js");
|
|
5
5
|
/**
|
|
6
6
|
* The first month a date picker shows. `activeMonths` always holds at least one month (`getInitialMonths` starts with
|
|
7
7
|
* one and navigation keeps the count), so the current month is never returned in practice: it only satisfies the
|
|
@@ -9,5 +9,5 @@ const get_current_year_month_and_date_1 = require("./get-current-year-month-and-
|
|
|
9
9
|
*/
|
|
10
10
|
function getFirstActiveMonth(activeMonths) {
|
|
11
11
|
var _a;
|
|
12
|
-
return (_a = activeMonths.at(0)) !== null && _a !== void 0 ? _a : (0,
|
|
12
|
+
return (_a = activeMonths.at(0)) !== null && _a !== void 0 ? _a : (0, get_current_year_month_and_date_ts_1.getCurrentYearMonthAndDate)();
|
|
13
13
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const get_first_active_month_ts_1 = require("./get-first-active-month.js");
|
|
4
|
+
const get_initial_months_ts_1 = require("./get-initial-months.js");
|
|
5
5
|
test("returns the first active month", () => {
|
|
6
|
-
const months = (0,
|
|
7
|
-
expect((0,
|
|
6
|
+
const months = (0, get_initial_months_ts_1.getInitialMonths)(2, new Date(2021, 9, 15));
|
|
7
|
+
expect((0, get_first_active_month_ts_1.getFirstActiveMonth)(months)).toBe(months.at(0));
|
|
8
8
|
});
|
|
9
9
|
test("falls back to the current month for an empty list", () => {
|
|
10
10
|
jest.useFakeTimers().setSystemTime(new Date(2024, 1, 10, 12));
|
|
11
|
-
expect((0,
|
|
11
|
+
expect((0, get_first_active_month_ts_1.getFirstActiveMonth)([])).toMatchObject({ year: 2024, month: 1 });
|
|
12
12
|
jest.useRealTimers();
|
|
13
13
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MonthType } from "./types";
|
|
1
|
+
import { MonthType } from "./types.ts";
|
|
2
2
|
export declare function getInitialMonths(numberOfMonths: number, startDate: Date | null): MonthType[];
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInitialMonths = getInitialMonths;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
5
|
+
const get_current_year_month_and_date_ts_1 = require("./get-current-year-month-and-date.js");
|
|
6
|
+
const get_date_month_and_year_ts_1 = require("./get-date-month-and-year.js");
|
|
7
7
|
function getInitialMonths(numberOfMonths, startDate) {
|
|
8
|
-
const firstMonth = startDate ? (0,
|
|
8
|
+
const firstMonth = startDate ? (0, get_date_month_and_year_ts_1.getDateMonthAndYear)(startDate) : (0, get_current_year_month_and_date_ts_1.getCurrentYearMonthAndDate)();
|
|
9
9
|
let months = [firstMonth];
|
|
10
10
|
if (numberOfMonths > 1) {
|
|
11
11
|
months = Array.from(Array(numberOfMonths - 1).keys()).reduce((m) => {
|
|
12
|
-
const nextDate = (0,
|
|
13
|
-
return m.concat([(0,
|
|
12
|
+
const nextDate = (0, date_string_ts_1.fromDateString)((0, date_string_ts_1.addMonths)((0, date_string_ts_1.toDateString)(m[m.length - 1].date), 1));
|
|
13
|
+
return m.concat([(0, get_date_month_and_year_ts_1.getDateMonthAndYear)(nextDate)]);
|
|
14
14
|
}, months);
|
|
15
15
|
}
|
|
16
16
|
return months;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const get_initial_months_ts_1 = require("./get-initial-months.js");
|
|
4
4
|
test("getInitialMonths", () => {
|
|
5
|
-
expect((0,
|
|
5
|
+
expect((0, get_initial_months_ts_1.getInitialMonths)(1, new Date("2021-09-15"))).toStrictEqual([
|
|
6
6
|
{
|
|
7
7
|
date: new Date("2021-09-01T00:00:00Z"),
|
|
8
8
|
month: 8,
|
|
@@ -11,7 +11,7 @@ test("getInitialMonths", () => {
|
|
|
11
11
|
]);
|
|
12
12
|
});
|
|
13
13
|
test("getInitialMonths 2 months", () => {
|
|
14
|
-
expect((0,
|
|
14
|
+
expect((0, get_initial_months_ts_1.getInitialMonths)(2, new Date("2021-09-15"))).toStrictEqual([
|
|
15
15
|
{
|
|
16
16
|
date: new Date("2021-09-01T00:00:00Z"),
|
|
17
17
|
month: 8,
|
|
@@ -26,7 +26,7 @@ test("getInitialMonths 2 months", () => {
|
|
|
26
26
|
});
|
|
27
27
|
// ensures that it works correctly on DST change
|
|
28
28
|
test("getInitialMonths March", () => {
|
|
29
|
-
expect((0,
|
|
29
|
+
expect((0, get_initial_months_ts_1.getInitialMonths)(2, new Date("2021-03-15"))).toStrictEqual([
|
|
30
30
|
{
|
|
31
31
|
date: new Date("2021-03-01T00:00:00Z"),
|
|
32
32
|
month: 2,
|
|
@@ -42,7 +42,7 @@ test("getInitialMonths March", () => {
|
|
|
42
42
|
test("getInitialMonths without date", () => {
|
|
43
43
|
jest.useFakeTimers();
|
|
44
44
|
jest.setSystemTime(new Date("2021-09-15"));
|
|
45
|
-
expect((0,
|
|
45
|
+
expect((0, get_initial_months_ts_1.getInitialMonths)(1, null)).toStrictEqual([
|
|
46
46
|
{
|
|
47
47
|
date: new Date("2021-09-01T00:00:00Z"),
|
|
48
48
|
month: 8,
|
package/utils/get-months.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMonths = getMonths;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
function getMonths({ year, monthLabelFormat = (date) => (0,
|
|
9
|
-
const yearStart = (0,
|
|
10
|
-
const yearEnd = (0,
|
|
11
|
-
return (0,
|
|
12
|
-
const date = (0,
|
|
4
|
+
const create_date_string_ts_1 = require("./create-date-string.js");
|
|
5
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
6
|
+
const dayjs_utils_ts_1 = require("./dayjs-utils.js");
|
|
7
|
+
const get_each_ts_1 = require("./get-each.js");
|
|
8
|
+
function getMonths({ year, monthLabelFormat = (date) => (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).format("MMMM"), }) {
|
|
9
|
+
const yearStart = (0, create_date_string_ts_1.createDateString)(year, 0);
|
|
10
|
+
const yearEnd = (0, create_date_string_ts_1.createDateString)(year, 11);
|
|
11
|
+
return (0, get_each_ts_1.getEach)(yearStart, yearEnd, "month").map((d) => {
|
|
12
|
+
const date = (0, date_string_ts_1.fromDateString)(d);
|
|
13
13
|
return { date, monthLabel: monthLabelFormat(date) };
|
|
14
14
|
});
|
|
15
15
|
}
|
package/utils/get-months.test.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const dayjs_utils_ts_1 = require("./dayjs-utils.js");
|
|
4
|
+
const get_months_ts_1 = require("./get-months.js");
|
|
5
5
|
test("getMonths", () => {
|
|
6
|
-
expect((0,
|
|
6
|
+
expect((0, get_months_ts_1.getMonths)({ year: 2021 })).toStrictEqual([
|
|
7
7
|
{ monthLabel: "January", date: new Date("2021-01-01T00:00:00Z") },
|
|
8
8
|
{ monthLabel: "February", date: new Date("2021-02-01T00:00:00Z") },
|
|
9
9
|
{ monthLabel: "March", date: new Date("2021-03-01T00:00:00Z") },
|
|
@@ -19,7 +19,7 @@ test("getMonths", () => {
|
|
|
19
19
|
]);
|
|
20
20
|
});
|
|
21
21
|
test("getMonths with custom format", () => {
|
|
22
|
-
expect((0,
|
|
22
|
+
expect((0, get_months_ts_1.getMonths)({ year: 2021, monthLabelFormat: (date) => (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).format("MM") })).toStrictEqual([
|
|
23
23
|
{ monthLabel: "01", date: new Date("2021-01-01T00:00:00Z") },
|
|
24
24
|
{ monthLabel: "02", date: new Date("2021-02-01T00:00:00Z") },
|
|
25
25
|
{ monthLabel: "03", date: new Date("2021-03-01T00:00:00Z") },
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MonthType } from "./types";
|
|
1
|
+
import { MonthType } from "./types.ts";
|
|
2
2
|
export declare function getNextActiveMonth(activeMonth: MonthType[], numberOfMonths: number, counter: number, step?: number): MonthType[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextActiveMonth = getNextActiveMonth;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
5
|
+
const get_date_month_and_year_ts_1 = require("./get-date-month-and-year.js");
|
|
6
6
|
function getNextActiveMonth(activeMonth, numberOfMonths, counter, step) {
|
|
7
7
|
let prevMonth;
|
|
8
8
|
if (step) {
|
|
@@ -11,15 +11,15 @@ function getNextActiveMonth(activeMonth, numberOfMonths, counter, step) {
|
|
|
11
11
|
else {
|
|
12
12
|
prevMonth = counter > 0 ? activeMonth.length - 1 : 0;
|
|
13
13
|
}
|
|
14
|
-
let prevMonthStr = (0,
|
|
14
|
+
let prevMonthStr = (0, date_string_ts_1.toDateString)(activeMonth[prevMonth].date);
|
|
15
15
|
return Array.from(Array(numberOfMonths).keys()).reduce((m) => {
|
|
16
16
|
if (m.length === 0) {
|
|
17
|
-
prevMonthStr = (0,
|
|
17
|
+
prevMonthStr = (0, date_string_ts_1.addMonths)(prevMonthStr, counter);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
prevMonthStr = (0,
|
|
20
|
+
prevMonthStr = (0, date_string_ts_1.addMonths)(prevMonthStr, counter >= 0 ? 1 : -1);
|
|
21
21
|
}
|
|
22
|
-
const monthType = (0,
|
|
22
|
+
const monthType = (0, get_date_month_and_year_ts_1.getDateMonthAndYear)(new Date(prevMonthStr));
|
|
23
23
|
return counter > 0 ? m.concat([monthType]) : [monthType].concat(m);
|
|
24
24
|
}, []);
|
|
25
25
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const get_next_active_month_ts_1 = require("./get-next-active-month.js");
|
|
4
4
|
test("getNextActiveMonth", () => {
|
|
5
|
-
expect((0,
|
|
5
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([{ year: 2021, month: 0, date: new Date("2021-01-01") }], 1, 1)).toStrictEqual([
|
|
6
6
|
{ year: 2021, month: 1, date: new Date("2021-02-01T00:00:00Z") },
|
|
7
7
|
]);
|
|
8
|
-
expect((0,
|
|
8
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([{ year: 2021, month: 9, date: new Date("2021-10-01") }], 1, 1)).toStrictEqual([
|
|
9
9
|
{ year: 2021, month: 10, date: new Date("2021-11-01T00:00:00Z") },
|
|
10
10
|
]);
|
|
11
11
|
});
|
|
12
12
|
test("getNextActiveMonth with 2 months", () => {
|
|
13
|
-
expect((0,
|
|
13
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([
|
|
14
14
|
{ year: 2021, month: 0, date: new Date("2021-01-01") },
|
|
15
15
|
{ year: 2021, month: 1, date: new Date("2021-02-01") },
|
|
16
16
|
], 2, 1)).toStrictEqual([
|
|
@@ -19,7 +19,7 @@ test("getNextActiveMonth with 2 months", () => {
|
|
|
19
19
|
]);
|
|
20
20
|
});
|
|
21
21
|
test("getNextActiveMonth with 2 months and step", () => {
|
|
22
|
-
expect((0,
|
|
22
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([
|
|
23
23
|
{ year: 2021, month: 0, date: new Date("2021-01-01") },
|
|
24
24
|
{ year: 2021, month: 1, date: new Date("2021-02-01") },
|
|
25
25
|
], 2, 1, 1)).toStrictEqual([
|
|
@@ -28,7 +28,7 @@ test("getNextActiveMonth with 2 months and step", () => {
|
|
|
28
28
|
]);
|
|
29
29
|
});
|
|
30
30
|
test("getNextActiveMonth with 2 months and counter 0", () => {
|
|
31
|
-
expect((0,
|
|
31
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([
|
|
32
32
|
{ year: 2021, month: 0, date: new Date("2021-01-01") },
|
|
33
33
|
{ year: 2021, month: 1, date: new Date("2021-02-01") },
|
|
34
34
|
], 2, 0)).toStrictEqual([
|
|
@@ -37,7 +37,7 @@ test("getNextActiveMonth with 2 months and counter 0", () => {
|
|
|
37
37
|
]);
|
|
38
38
|
});
|
|
39
39
|
test("getNextActiveMonth with 2 months and step and counter 0", () => {
|
|
40
|
-
expect((0,
|
|
40
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([
|
|
41
41
|
{ year: 2021, month: 0, date: new Date("2021-01-01") },
|
|
42
42
|
{ year: 2021, month: 1, date: new Date("2021-02-01") },
|
|
43
43
|
], 2, 0, 1)).toStrictEqual([
|
|
@@ -46,7 +46,7 @@ test("getNextActiveMonth with 2 months and step and counter 0", () => {
|
|
|
46
46
|
]);
|
|
47
47
|
});
|
|
48
48
|
test("getNextActiveMonth with 2 months and negative counter", () => {
|
|
49
|
-
expect((0,
|
|
49
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([
|
|
50
50
|
{ year: 2021, month: 0, date: new Date("2021-01-01") },
|
|
51
51
|
{ year: 2021, month: 1, date: new Date("2021-02-01") },
|
|
52
52
|
], 2, -1)).toStrictEqual([
|
|
@@ -55,7 +55,7 @@ test("getNextActiveMonth with 2 months and negative counter", () => {
|
|
|
55
55
|
]);
|
|
56
56
|
});
|
|
57
57
|
test("getNextActiveMonth with 2 months and step and negative counter", () => {
|
|
58
|
-
expect((0,
|
|
58
|
+
expect((0, get_next_active_month_ts_1.getNextActiveMonth)([
|
|
59
59
|
{ year: 2021, month: 0, date: new Date("2021-01-01") },
|
|
60
60
|
{ year: 2021, month: 1, date: new Date("2021-02-01") },
|
|
61
61
|
], 2, -1, 1)).toStrictEqual([
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getWeekdayLabels = getWeekdayLabels;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
function getWeekdayLabels({ firstDayOfWeek = 0, weekdayLabelFormat = (date) => (0,
|
|
8
|
-
const now = (0,
|
|
4
|
+
const date_string_ts_1 = require("./date-string.js");
|
|
5
|
+
const dayjs_utils_ts_1 = require("./dayjs-utils.js");
|
|
6
|
+
const get_each_ts_1 = require("./get-each.js");
|
|
7
|
+
function getWeekdayLabels({ firstDayOfWeek = 0, weekdayLabelFormat = (date) => (0, dayjs_utils_ts_1.dayjsEnWithTz)(date).format("dd"), }) {
|
|
8
|
+
const now = (0, dayjs_utils_ts_1.dayjsEnWithTz)();
|
|
9
9
|
const start = now.startOf("week").add(firstDayOfWeek, "day").format("YYYY-MM-DD");
|
|
10
10
|
const end = now.endOf("week").add(firstDayOfWeek, "day").format("YYYY-MM-DD");
|
|
11
|
-
return (0,
|
|
11
|
+
return (0, get_each_ts_1.getEach)(start, end, "day").map((d) => weekdayLabelFormat((0, date_string_ts_1.fromDateString)(d)));
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import "dayjs/locale/cs";
|
|
1
|
+
import "dayjs/locale/cs.js";
|