@uxf/datepicker 11.111.0-canary.1 → 11.111.2
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-navigation.d.ts +3 -4
- package/hooks/use-date-picker-navigation.js +34 -30
- package/hooks/use-date-picker-navigation.test.js +4 -40
- package/hooks/use-date-picker.js +26 -40
- package/hooks/use-date-picker.test.js +2 -2
- package/hooks/use-date-range-picker.js +76 -103
- package/hooks/use-day.js +11 -12
- package/hooks/use-decade.js +8 -9
- package/package.json +4 -9
- package/utils/can-select-range.d.ts +5 -6
- package/utils/can-select-range.js +19 -7
- package/utils/can-select-range.test.js +27 -30
- package/utils/dayjs-utils.d.ts +1 -0
- package/utils/dayjs-utils.js +5 -1
- package/utils/get-current-year-month-and-date.js +2 -1
- package/utils/get-date-invervals.js +5 -2
- package/utils/get-date-month-and-year.js +5 -6
- package/utils/get-days.js +9 -12
- package/utils/get-each.d.ts +1 -2
- package/utils/get-each.js +9 -37
- package/utils/get-each.test.js +19 -34
- package/utils/get-initial-months.js +6 -3
- package/utils/get-months.js +7 -7
- package/utils/get-next-active-month.js +10 -6
- package/utils/get-weekday-labels.js +2 -4
- package/utils/get-years.js +4 -5
- package/utils/is-date-blocked.d.ts +6 -7
- package/utils/is-date-blocked.js +7 -6
- package/utils/is-date-blocked.test.js +11 -108
- package/utils/is-date-hovered.d.ts +5 -6
- package/utils/is-date-hovered.js +24 -17
- package/utils/is-date-hovered.test.js +25 -42
- package/utils/is-date-inside-range.d.ts +1 -2
- package/utils/is-date-inside-range.js +2 -1
- package/utils/is-date-selected.test.js +8 -16
- package/utils/is-end-date.d.ts +1 -2
- package/utils/is-end-date.js +2 -1
- package/utils/is-end-date.test.js +6 -11
- package/utils/is-first-or-last-selected-date.d.ts +1 -2
- package/utils/is-first-or-last-selected-date.js +3 -1
- package/utils/is-first-or-last-selected-date.test.js +6 -9
- package/utils/is-in-unavailable-dates.d.ts +1 -2
- package/utils/is-in-unavailable-dates.js +2 -1
- package/utils/is-in-unavailable-dates.test.js +6 -10
- package/utils/is-start-date.d.ts +1 -2
- package/utils/is-start-date.js +2 -1
- package/utils/is-start-date.test.js +6 -12
- package/jest.dst.config.js +0 -22
- package/jest.dst.global-setup.js +0 -14
- package/utils/date-string.d.ts +0 -34
- package/utils/date-string.js +0 -64
- package/utils/date-string.test.d.ts +0 -1
- package/utils/date-string.test.js +0 -63
- package/utils/dst-robustness.test.d.ts +0 -11
- package/utils/dst-robustness.test.js +0 -328
package/hooks/use-day.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useDay = useDay;
|
|
4
4
|
const empty_array_1 = require("@uxf/core/constants/empty-array");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
6
|
+
const dayjs_utils_1 = require("../utils/dayjs-utils");
|
|
7
7
|
const get_date_invervals_1 = require("../utils/get-date-invervals");
|
|
8
8
|
function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates, }) {
|
|
9
9
|
var _a;
|
|
@@ -12,7 +12,7 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
12
12
|
const disabledDates = [...unavailableDates, ...disabledDatesFromConfig].filter((day, index, self) => index === self.findIndex((d) => d.getTime() === day.getTime()));
|
|
13
13
|
const onClick = (0, react_1.useCallback)(() => onDateSelect(date), [date, onDateSelect]);
|
|
14
14
|
const onMouseEnter = (0, react_1.useCallback)(() => onDateHover(date), [date, onDateHover]);
|
|
15
|
-
const isToday = (0,
|
|
15
|
+
const isToday = (0, dayjs_utils_1.dayjsEnWithTz)().isSame(date, "day");
|
|
16
16
|
(0, react_1.useEffect)(() => {
|
|
17
17
|
if (dayRef && dayRef.current && isDateFocused(date)) {
|
|
18
18
|
dayRef.current.focus({
|
|
@@ -25,29 +25,28 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
25
25
|
e.preventDefault();
|
|
26
26
|
switch (e.key) {
|
|
27
27
|
case "ArrowRight":
|
|
28
|
-
onDateFocus((0,
|
|
28
|
+
onDateFocus((0, dayjs_utils_1.dayjsEnRaw)(date).add(1, "day").toDate());
|
|
29
29
|
break;
|
|
30
30
|
case "ArrowLeft":
|
|
31
|
-
onDateFocus((0,
|
|
31
|
+
onDateFocus((0, dayjs_utils_1.dayjsEnRaw)(date).subtract(1, "day").toDate());
|
|
32
32
|
break;
|
|
33
33
|
case "ArrowUp":
|
|
34
|
-
onDateFocus((0,
|
|
34
|
+
onDateFocus((0, dayjs_utils_1.dayjsEnRaw)(date).subtract(7, "day").toDate());
|
|
35
35
|
break;
|
|
36
36
|
case "ArrowDown":
|
|
37
|
-
onDateFocus((0,
|
|
37
|
+
onDateFocus((0, dayjs_utils_1.dayjsEnRaw)(date).add(7, "day").toDate());
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}, [date, onDateFocus]);
|
|
42
42
|
const dateIntervals = (0, get_date_invervals_1.getDateIntervals)(disabledDates);
|
|
43
|
-
const dateStr = (0, date_string_1.toDateString)(date);
|
|
44
43
|
const _isFirstUnavailableDate = () => {
|
|
45
|
-
return dateIntervals.some((interval) => (0,
|
|
44
|
+
return dateIntervals.some((interval) => (0, dayjs_utils_1.dayjsEnRaw)(interval.start).isSame(date, "day"));
|
|
46
45
|
};
|
|
47
46
|
const _isLastUnavailableDate = () => {
|
|
48
|
-
return dateIntervals.some((interval) => (0,
|
|
47
|
+
return dateIntervals.some((interval) => (0, dayjs_utils_1.dayjsEnRaw)(interval.end).isSame(date, "day"));
|
|
49
48
|
};
|
|
50
|
-
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.dates.some((configDay) => (0,
|
|
49
|
+
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter((config) => config.dates.some((configDay) => (0, dayjs_utils_1.dayjsEnRaw)(configDay).isSame(date, "day")));
|
|
51
50
|
const flags = applicableDatesConfigs === null || applicableDatesConfigs === void 0 ? void 0 : applicableDatesConfigs.reduce((acc, curr) => {
|
|
52
51
|
if (!curr.flag) {
|
|
53
52
|
return acc;
|
|
@@ -55,8 +54,8 @@ function useDay({ date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateF
|
|
|
55
54
|
const intervals = (0, get_date_invervals_1.getDateIntervals)(curr.dates);
|
|
56
55
|
acc.push({
|
|
57
56
|
flag: curr.flag,
|
|
58
|
-
isFirst: intervals.some((interval) => (0,
|
|
59
|
-
isLast: intervals.some((interval) => (0,
|
|
57
|
+
isFirst: intervals.some((interval) => (0, dayjs_utils_1.dayjsEnRaw)(interval.start).isSame(date, "day")),
|
|
58
|
+
isLast: intervals.some((interval) => (0, dayjs_utils_1.dayjsEnRaw)(interval.end).isSame(date, "day")),
|
|
60
59
|
});
|
|
61
60
|
return acc;
|
|
62
61
|
}, []);
|
package/hooks/use-decade.js
CHANGED
|
@@ -11,13 +11,12 @@ exports.yearLabelFormatFn = yearLabelFormatFn;
|
|
|
11
11
|
const decadeLabelFormatFn = (start, end) => `${(0, dayjs_utils_1.dayjsEnWithTz)(start).format("YYYY")} \u2013 ${(0, dayjs_utils_1.dayjsEnWithTz)(end).format("YYYY")}`;
|
|
12
12
|
exports.decadeLabelFormatFn = decadeLabelFormatFn;
|
|
13
13
|
function useDecade({ yearLabelFormat = exports.yearLabelFormatFn, decadeLabelFormat = exports.decadeLabelFormatFn, year, }) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return { years, decadeLabel };
|
|
14
|
+
const currentYear = new Date((0, create_date_string_1.createDateString)(year, 0));
|
|
15
|
+
const startYear = (0, dayjs_utils_1.dayjsEnWithTz)(currentYear).subtract(4, "years").startOf("year").toDate();
|
|
16
|
+
const endYear = (0, dayjs_utils_1.dayjsEnWithTz)(currentYear).add(4, "years").endOf("year").toDate();
|
|
17
|
+
const years = (0, react_1.useMemo)(() => (0, get_years_1.getYears)({ startYear, endYear, yearLabelFormat }), [endYear, startYear, yearLabelFormat]);
|
|
18
|
+
return {
|
|
19
|
+
years,
|
|
20
|
+
decadeLabel: decadeLabelFormat(startYear, endYear),
|
|
21
|
+
};
|
|
23
22
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/datepicker",
|
|
3
|
-
"version": "11.111.
|
|
3
|
+
"version": "11.111.2",
|
|
4
4
|
"description": "A set of React hooks to create an awesome datepicker.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc -P tsconfig.json",
|
|
8
|
-
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
9
|
-
"test:tz:prague": "TZ=Europe/Prague jest --config=jest.dst.config.js --no-coverage",
|
|
10
|
-
"test:tz:ny": "TZ=America/New_York jest --config=jest.dst.config.js --no-coverage",
|
|
11
|
-
"test:tz:tokyo": "TZ=Asia/Tokyo jest --config=jest.dst.config.js --no-coverage",
|
|
12
|
-
"test:dst": "TZ=America/New_York jest --config=jest.dst.config.js --no-coverage",
|
|
13
|
-
"test:tz": "npm run test:tz:prague && npm run test:tz:ny && npm run test:tz:tokyo"
|
|
8
|
+
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
14
9
|
},
|
|
15
10
|
"publishConfig": {
|
|
16
11
|
"access": "public"
|
|
@@ -26,7 +21,7 @@
|
|
|
26
21
|
},
|
|
27
22
|
"homepage": "https://gitlab.com/uxf-npm/datepicker#readme",
|
|
28
23
|
"peerDependencies": {
|
|
29
|
-
"@uxf/core": "11.
|
|
24
|
+
"@uxf/core": "11.111.2",
|
|
30
25
|
"dayjs": "^1.11.19",
|
|
31
26
|
"react": ">=18.2.0",
|
|
32
27
|
"react-dom": ">=18.2.0"
|
|
@@ -34,7 +29,7 @@
|
|
|
34
29
|
"devDependencies": {
|
|
35
30
|
"@types/react": "18.3.27",
|
|
36
31
|
"@types/react-dom": "18.3.7",
|
|
37
|
-
"@uxf/core": "11.
|
|
32
|
+
"@uxf/core": "11.111.2",
|
|
38
33
|
"dayjs": "^1.11.19",
|
|
39
34
|
"react": "18.3.1",
|
|
40
35
|
"react-dom": "18.3.1"
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { DateString } from "@uxf/core/date";
|
|
2
1
|
export interface CanSelectRangeProps {
|
|
3
|
-
startDate:
|
|
4
|
-
endDate:
|
|
5
|
-
isDateBlocked: ((date:
|
|
2
|
+
startDate: Date;
|
|
3
|
+
endDate: Date | null;
|
|
4
|
+
isDateBlocked: ((date: Date) => boolean) | null;
|
|
6
5
|
minBookingDays: number;
|
|
7
6
|
exactMinBookingDays?: boolean;
|
|
8
|
-
minBookingDate?:
|
|
9
|
-
maxBookingDate?:
|
|
7
|
+
minBookingDate?: Date;
|
|
8
|
+
maxBookingDate?: Date;
|
|
10
9
|
}
|
|
11
10
|
export declare function canSelectRange({ startDate, endDate, isDateBlocked, minBookingDays, exactMinBookingDays, minBookingDate, maxBookingDate, }: CanSelectRangeProps): boolean;
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.canSelectRange = canSelectRange;
|
|
4
|
-
const
|
|
4
|
+
const dayjs_utils_1 = require("./dayjs-utils");
|
|
5
5
|
const get_each_1 = require("./get-each");
|
|
6
6
|
// eslint-disable-next-line complexity
|
|
7
7
|
function canSelectRange({ startDate, endDate, isDateBlocked, minBookingDays, exactMinBookingDays, minBookingDate, maxBookingDate, }) {
|
|
8
|
-
const isStartDateAfterOrEqualMinDate = minBookingDate
|
|
8
|
+
const isStartDateAfterOrEqualMinDate = minBookingDate
|
|
9
|
+
? !(0, dayjs_utils_1.dayjsEnRaw)(startDate).isBefore((0, dayjs_utils_1.dayjsEnRaw)(minBookingDate).subtract(1, "day"))
|
|
10
|
+
: true;
|
|
9
11
|
const isStartDateBeforeOrEqualMaxDate = maxBookingDate
|
|
10
|
-
? (0,
|
|
12
|
+
? !(0, dayjs_utils_1.dayjsEnRaw)(startDate)
|
|
13
|
+
.add(minBookingDays - 1, "day")
|
|
14
|
+
.isAfter(maxBookingDate)
|
|
15
|
+
: true;
|
|
16
|
+
const isEndDatBeforeOrEqualMaxDate = maxBookingDate
|
|
17
|
+
? !(0, dayjs_utils_1.dayjsEnRaw)(endDate)
|
|
18
|
+
.add(minBookingDays - 1, "day")
|
|
19
|
+
.isAfter(maxBookingDate)
|
|
11
20
|
: true;
|
|
12
|
-
const isEndDatBeforeOrEqualMaxDate = maxBookingDate && endDate ? (0, date_string_1.addDays)(endDate, minBookingDays - 1) <= maxBookingDate : true;
|
|
13
21
|
if (!isStartDateAfterOrEqualMinDate || !isStartDateBeforeOrEqualMaxDate || !isEndDatBeforeOrEqualMaxDate) {
|
|
14
22
|
return false;
|
|
15
23
|
}
|
|
@@ -22,11 +30,15 @@ function canSelectRange({ startDate, endDate, isDateBlocked, minBookingDays, exa
|
|
|
22
30
|
if (!isDateBlocked) {
|
|
23
31
|
return true;
|
|
24
32
|
}
|
|
25
|
-
return !(0, get_each_1.getEach)(startDate, (0,
|
|
33
|
+
return !(0, get_each_1.getEach)(startDate, (0, dayjs_utils_1.dayjsEnRaw)(startDate)
|
|
34
|
+
.add(minBookingDays - 1, "day")
|
|
35
|
+
.toDate(), "day").some(isDateBlocked);
|
|
26
36
|
}
|
|
27
37
|
else if (endDate && !exactMinBookingDays) {
|
|
28
|
-
const minBookingDaysDate = (0,
|
|
29
|
-
|
|
38
|
+
const minBookingDaysDate = (0, dayjs_utils_1.dayjsEnWithTz)(startDate)
|
|
39
|
+
.add(minBookingDays - 1, "day")
|
|
40
|
+
.toDate();
|
|
41
|
+
if ((0, dayjs_utils_1.dayjsEnWithTz)(endDate).isBefore(minBookingDaysDate)) {
|
|
30
42
|
return false;
|
|
31
43
|
}
|
|
32
44
|
if (!isDateBlocked) {
|
|
@@ -4,7 +4,7 @@ const can_select_range_1 = require("./can-select-range");
|
|
|
4
4
|
test("canSelectRange", () => {
|
|
5
5
|
// start day only
|
|
6
6
|
expect((0, can_select_range_1.canSelectRange)({
|
|
7
|
-
startDate: "2021-08-08",
|
|
7
|
+
startDate: new Date("2021-08-08"),
|
|
8
8
|
endDate: null,
|
|
9
9
|
minBookingDays: 1,
|
|
10
10
|
minBookingDate: undefined,
|
|
@@ -14,8 +14,8 @@ test("canSelectRange", () => {
|
|
|
14
14
|
})).toBe(true);
|
|
15
15
|
// start and end date
|
|
16
16
|
expect((0, can_select_range_1.canSelectRange)({
|
|
17
|
-
startDate: "2021-08-08",
|
|
18
|
-
endDate: "2021-08-08",
|
|
17
|
+
startDate: new Date("2021-08-08"),
|
|
18
|
+
endDate: new Date("2021-08-08"),
|
|
19
19
|
minBookingDays: 1,
|
|
20
20
|
minBookingDate: undefined,
|
|
21
21
|
maxBookingDate: undefined,
|
|
@@ -24,8 +24,18 @@ test("canSelectRange", () => {
|
|
|
24
24
|
})).toBe(true);
|
|
25
25
|
// minBookingDays longer than range
|
|
26
26
|
expect((0, can_select_range_1.canSelectRange)({
|
|
27
|
-
startDate: "2021-08-08",
|
|
28
|
-
endDate: "2021-08-08",
|
|
27
|
+
startDate: new Date("2021-08-08"),
|
|
28
|
+
endDate: new Date("2021-08-08"),
|
|
29
|
+
minBookingDays: 2,
|
|
30
|
+
minBookingDate: undefined,
|
|
31
|
+
maxBookingDate: undefined,
|
|
32
|
+
exactMinBookingDays: false,
|
|
33
|
+
isDateBlocked: () => false,
|
|
34
|
+
})).toBe(false);
|
|
35
|
+
// minBookingDays longer than range
|
|
36
|
+
expect((0, can_select_range_1.canSelectRange)({
|
|
37
|
+
startDate: new Date("2021-08-08"),
|
|
38
|
+
endDate: new Date("2021-08-08"),
|
|
29
39
|
minBookingDays: 2,
|
|
30
40
|
minBookingDate: undefined,
|
|
31
41
|
maxBookingDate: undefined,
|
|
@@ -34,8 +44,8 @@ test("canSelectRange", () => {
|
|
|
34
44
|
})).toBe(false);
|
|
35
45
|
// blocked date
|
|
36
46
|
expect((0, can_select_range_1.canSelectRange)({
|
|
37
|
-
startDate: "2021-08-08",
|
|
38
|
-
endDate: "2021-08-08",
|
|
47
|
+
startDate: new Date("2021-08-08"),
|
|
48
|
+
endDate: new Date("2021-08-08"),
|
|
39
49
|
minBookingDays: 1,
|
|
40
50
|
minBookingDate: undefined,
|
|
41
51
|
maxBookingDate: undefined,
|
|
@@ -44,50 +54,37 @@ test("canSelectRange", () => {
|
|
|
44
54
|
})).toBe(false);
|
|
45
55
|
// before minBookingDate
|
|
46
56
|
expect((0, can_select_range_1.canSelectRange)({
|
|
47
|
-
startDate: "2021-08-05",
|
|
48
|
-
endDate: "2021-08-12",
|
|
57
|
+
startDate: new Date("2021-08-05"),
|
|
58
|
+
endDate: new Date("2021-08-12"),
|
|
49
59
|
minBookingDays: 1,
|
|
50
|
-
minBookingDate: "2021-08-10",
|
|
60
|
+
minBookingDate: new Date("2021-08-10"),
|
|
51
61
|
maxBookingDate: undefined,
|
|
52
62
|
exactMinBookingDays: false,
|
|
53
63
|
isDateBlocked: () => false,
|
|
54
64
|
})).toBe(false);
|
|
55
65
|
// after maxBookingDate
|
|
56
66
|
expect((0, can_select_range_1.canSelectRange)({
|
|
57
|
-
startDate: "2021-08-01",
|
|
58
|
-
endDate: "2021-08-08",
|
|
67
|
+
startDate: new Date("2021-08-01"),
|
|
68
|
+
endDate: new Date("2021-08-08"),
|
|
59
69
|
minBookingDays: 1,
|
|
60
70
|
minBookingDate: undefined,
|
|
61
|
-
maxBookingDate: "2021-08-06",
|
|
71
|
+
maxBookingDate: new Date("2021-08-06"),
|
|
62
72
|
exactMinBookingDays: false,
|
|
63
73
|
isDateBlocked: () => false,
|
|
64
74
|
})).toBe(false);
|
|
65
75
|
// exactMinBookingDays
|
|
66
76
|
expect((0, can_select_range_1.canSelectRange)({
|
|
67
|
-
startDate: "2021-08-01",
|
|
68
|
-
endDate: "2021-08-08",
|
|
77
|
+
startDate: new Date("2021-08-01"),
|
|
78
|
+
endDate: new Date("2021-08-08"),
|
|
69
79
|
minBookingDays: 8,
|
|
70
80
|
minBookingDate: undefined,
|
|
71
81
|
maxBookingDate: undefined,
|
|
72
82
|
exactMinBookingDays: true,
|
|
73
83
|
isDateBlocked: () => false,
|
|
74
84
|
})).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
test("canSelectRange DST fall-back (Oct 25 2026)", () => {
|
|
77
|
-
expect((0, can_select_range_1.canSelectRange)({
|
|
78
|
-
startDate: "2026-10-25",
|
|
79
|
-
endDate: "2026-10-26",
|
|
80
|
-
minBookingDays: 2,
|
|
81
|
-
minBookingDate: undefined,
|
|
82
|
-
maxBookingDate: undefined,
|
|
83
|
-
exactMinBookingDays: false,
|
|
84
|
-
isDateBlocked: () => false,
|
|
85
|
-
})).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
test("canSelectRange DST spring-forward (Mar 29 2026)", () => {
|
|
88
85
|
expect((0, can_select_range_1.canSelectRange)({
|
|
89
|
-
startDate: "2026-
|
|
90
|
-
endDate: "2026-
|
|
86
|
+
startDate: new Date("2026-10-25"),
|
|
87
|
+
endDate: new Date("2026-10-26"),
|
|
91
88
|
minBookingDays: 2,
|
|
92
89
|
minBookingDate: undefined,
|
|
93
90
|
maxBookingDate: undefined,
|
package/utils/dayjs-utils.d.ts
CHANGED
package/utils/dayjs-utils.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.dayjsEnWithTz = void 0;
|
|
39
|
+
exports.dayjsEnWithTz = exports.dayjsEnRaw = 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,6 +45,10 @@ 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
|
+
const dayjsEnRaw = (value) => {
|
|
49
|
+
return (0, dayjs_1.default)(value).locale("en");
|
|
50
|
+
};
|
|
51
|
+
exports.dayjsEnRaw = dayjsEnRaw;
|
|
48
52
|
const dayjsEnWithTz = (value, tz = "UTC") => {
|
|
49
53
|
return (0, dayjs_1.default)(value).tz(tz).locale("en");
|
|
50
54
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCurrentYearMonthAndDate = getCurrentYearMonthAndDate;
|
|
4
|
+
const dayjs_utils_1 = require("./dayjs-utils");
|
|
4
5
|
const get_date_month_and_year_1 = require("./get-date-month-and-year");
|
|
5
6
|
function getCurrentYearMonthAndDate() {
|
|
6
|
-
return (0, get_date_month_and_year_1.getDateMonthAndYear)(
|
|
7
|
+
return (0, get_date_month_and_year_1.getDateMonthAndYear)((0, dayjs_utils_1.dayjsEnWithTz)().startOf("day").toDate());
|
|
7
8
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDateIntervals = getDateIntervals;
|
|
4
4
|
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
5
|
-
const
|
|
5
|
+
const dayjs_utils_1 = require("./dayjs-utils");
|
|
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,9 @@ 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
|
-
|
|
14
|
+
const nextDate = (0, dayjs_utils_1.dayjsEnRaw)(currentEnd).add(1, "day").toDate();
|
|
15
|
+
// If the current date matches the expected next date, it's contiguous
|
|
16
|
+
if ((0, dayjs_utils_1.dayjsEnRaw)(currentDate).isSame(nextDate, "day")) {
|
|
15
17
|
currentEnd = currentDate;
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
@@ -21,6 +23,7 @@ function getDateIntervals(dates) {
|
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
if ((0, is_not_nil_1.isNotNil)(firstSortedDate)) {
|
|
26
|
+
// Push the last interval
|
|
24
27
|
intervals.push({ start: currentStart, end: currentEnd });
|
|
25
28
|
}
|
|
26
29
|
return intervals;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDateMonthAndYear = getDateMonthAndYear;
|
|
4
|
-
const
|
|
5
|
-
const date_string_1 = require("./date-string");
|
|
4
|
+
const dayjs_utils_1 = require("./dayjs-utils");
|
|
6
5
|
function getDateMonthAndYear(date) {
|
|
7
|
-
const
|
|
8
|
-
const year =
|
|
9
|
-
const month =
|
|
6
|
+
const day = (0, dayjs_utils_1.dayjsEnWithTz)(date).startOf("month").toDate();
|
|
7
|
+
const year = (0, dayjs_utils_1.dayjsEnWithTz)(day).year();
|
|
8
|
+
const month = (0, dayjs_utils_1.dayjsEnWithTz)(day).month();
|
|
10
9
|
return {
|
|
11
10
|
year,
|
|
12
11
|
month,
|
|
13
|
-
date:
|
|
12
|
+
date: day,
|
|
14
13
|
};
|
|
15
14
|
}
|
package/utils/get-days.js
CHANGED
|
@@ -2,38 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDays = getDays;
|
|
4
4
|
const create_date_string_1 = require("./create-date-string");
|
|
5
|
-
const date_string_1 = require("./date-string");
|
|
6
5
|
const dayjs_utils_1 = require("./dayjs-utils");
|
|
7
6
|
const get_each_1 = require("./get-each");
|
|
8
7
|
function getDays({ year, month, firstDayOfWeek = 0, dayLabelFormat = (date) => (0, dayjs_utils_1.dayjsEnWithTz)(date).format("DD"), }) {
|
|
9
8
|
const date = new Date((0, create_date_string_1.createDateString)(year, month));
|
|
10
9
|
const lastDayOfWeek = firstDayOfWeek + 7;
|
|
11
10
|
const monthStart = (0, dayjs_utils_1.dayjsEnWithTz)(date).startOf("month");
|
|
12
|
-
const monthStartStr = monthStart.format("YYYY-MM-DD");
|
|
13
11
|
const monthStartDay = monthStart.day();
|
|
14
12
|
const monthEnd = (0, dayjs_utils_1.dayjsEnWithTz)(date).endOf("month");
|
|
15
|
-
const monthEndStr = monthEnd.format("YYYY-MM-DD");
|
|
16
13
|
const monthEndDay = monthEnd.day();
|
|
17
14
|
const prevMonthDaysCount = monthStartDay >= firstDayOfWeek ? monthStartDay - firstDayOfWeek : 6 - firstDayOfWeek + monthStartDay + 1;
|
|
18
15
|
const prevMonthDays = prevMonthDaysCount > 0
|
|
19
|
-
? (0, get_each_1.getEach)((
|
|
16
|
+
? (0, get_each_1.getEach)(monthStart.subtract(prevMonthDaysCount, "days").toDate(), monthStart.subtract(1, "day").toDate(), "day").map((d) => ({
|
|
20
17
|
currentMonth: false,
|
|
21
|
-
date:
|
|
22
|
-
dayLabel: dayLabelFormat(
|
|
18
|
+
date: d,
|
|
19
|
+
dayLabel: dayLabelFormat(d),
|
|
23
20
|
}))
|
|
24
21
|
: [];
|
|
25
22
|
const nextMonthDaysCount = lastDayOfWeek - monthEndDay - 1;
|
|
26
23
|
const nextMonthDays = nextMonthDaysCount > 0 && nextMonthDaysCount < 7
|
|
27
|
-
? (0, get_each_1.getEach)((
|
|
24
|
+
? (0, get_each_1.getEach)(monthEnd.add(1, "day").toDate(), monthEnd.add(nextMonthDaysCount, "days").toDate(), "day").map((d) => ({
|
|
28
25
|
currentMonth: false,
|
|
29
|
-
date:
|
|
30
|
-
dayLabel: dayLabelFormat(
|
|
26
|
+
date: d,
|
|
27
|
+
dayLabel: dayLabelFormat(d),
|
|
31
28
|
}))
|
|
32
29
|
: [];
|
|
33
|
-
const days = (0, get_each_1.getEach)(
|
|
30
|
+
const days = (0, get_each_1.getEach)(monthStart.toDate(), monthEnd.toDate(), "day").map((d) => ({
|
|
34
31
|
currentMonth: true,
|
|
35
|
-
date:
|
|
36
|
-
dayLabel: dayLabelFormat(
|
|
32
|
+
date: d,
|
|
33
|
+
dayLabel: dayLabelFormat(d),
|
|
37
34
|
}));
|
|
38
35
|
return [...prevMonthDays, ...days, ...nextMonthDays];
|
|
39
36
|
}
|
package/utils/get-each.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function getEach(start: DateString, end: DateString, type: "day" | "month" | "year"): DateString[];
|
|
1
|
+
export declare function getEach(start: Date, end: Date, type: "day" | "month" | "year"): Date[];
|
package/utils/get-each.js
CHANGED
|
@@ -1,46 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEach = getEach;
|
|
4
|
-
const
|
|
5
|
-
const date_string_1 = require("./date-string");
|
|
6
|
-
const DAY_MS = 86400000;
|
|
4
|
+
const dayjs_utils_1 = require("./dayjs-utils");
|
|
7
5
|
function getEach(start, end, type) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (startMs > endMs) {
|
|
12
|
-
throw new Error("start must precede end");
|
|
13
|
-
}
|
|
14
|
-
const count = Math.round((endMs - startMs) / DAY_MS) + 1;
|
|
15
|
-
const results = new Array(count);
|
|
16
|
-
for (let i = 0; i < count; i++) {
|
|
17
|
-
results[i] = (0, date_string_1.toDateString)(new Date(startMs + i * DAY_MS));
|
|
18
|
-
}
|
|
19
|
-
return results;
|
|
20
|
-
}
|
|
21
|
-
if (type === "month") {
|
|
22
|
-
const [sy, sm] = start.split("-").map(Number);
|
|
23
|
-
const [ey, em] = end.split("-").map(Number);
|
|
24
|
-
if (sy > ey || (sy === ey && sm > em)) {
|
|
25
|
-
throw new Error("start must precede end");
|
|
26
|
-
}
|
|
27
|
-
const count = (ey - sy) * 12 + (em - sm) + 1;
|
|
28
|
-
const results = new Array(count);
|
|
29
|
-
for (let i = 0; i < count; i++) {
|
|
30
|
-
const totalMonths = sm - 1 + i; // 0-indexed from start month
|
|
31
|
-
results[i] = (0, create_date_string_1.createDateString)(sy + Math.floor(totalMonths / 12), totalMonths % 12);
|
|
32
|
-
}
|
|
33
|
-
return results;
|
|
34
|
-
}
|
|
35
|
-
// type === "year"
|
|
36
|
-
const sy = parseInt(start.slice(0, 4), 10);
|
|
37
|
-
const ey = parseInt(end.slice(0, 4), 10);
|
|
38
|
-
if (sy > ey) {
|
|
6
|
+
const startOfStart = (0, dayjs_utils_1.dayjsEnWithTz)(start).startOf(type);
|
|
7
|
+
const startOfEnd = (0, dayjs_utils_1.dayjsEnWithTz)(end).startOf(type);
|
|
8
|
+
if (startOfStart.toDate().getTime() > startOfEnd.toDate().getTime()) {
|
|
39
9
|
throw new Error("start must precede end");
|
|
40
10
|
}
|
|
41
|
-
const results =
|
|
42
|
-
|
|
43
|
-
|
|
11
|
+
const results = [];
|
|
12
|
+
let current = startOfStart;
|
|
13
|
+
while (current.toDate().getTime() <= startOfEnd.toDate().getTime()) {
|
|
14
|
+
results.push(current.toDate());
|
|
15
|
+
current = current.add(1, type);
|
|
44
16
|
}
|
|
45
17
|
return results;
|
|
46
18
|
}
|
package/utils/get-each.test.js
CHANGED
|
@@ -2,45 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const get_each_1 = require("./get-each");
|
|
4
4
|
test("getEach day", () => {
|
|
5
|
-
expect((0, get_each_1.getEach)("2021-05-05", "2021-05-07", "day")).toStrictEqual([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
test("getEach day — DST spring-forward (Mar 29 2026)", () => {
|
|
11
|
-
expect((0, get_each_1.getEach)("2026-03-28", "2026-03-30", "day")).toStrictEqual(["2026-03-28", "2026-03-29", "2026-03-30"]);
|
|
12
|
-
});
|
|
13
|
-
test("getEach month", () => {
|
|
14
|
-
expect((0, get_each_1.getEach)("2021-05-05", "2021-08-07", "month")).toStrictEqual([
|
|
15
|
-
"2021-05-01",
|
|
16
|
-
"2021-06-01",
|
|
17
|
-
"2021-07-01",
|
|
18
|
-
"2021-08-01",
|
|
5
|
+
expect((0, get_each_1.getEach)(new Date("2021-05-05"), new Date("2021-05-07"), "day")).toStrictEqual([
|
|
6
|
+
new Date("2021-05-05T00:00:00Z"),
|
|
7
|
+
new Date("2021-05-06T00:00:00Z"),
|
|
8
|
+
new Date("2021-05-07T00:00:00Z"),
|
|
19
9
|
]);
|
|
20
10
|
});
|
|
21
|
-
test("getEach month
|
|
22
|
-
expect((0, get_each_1.getEach)("2021-
|
|
23
|
-
"2021-
|
|
24
|
-
"2021-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
11
|
+
test("getEach month", () => {
|
|
12
|
+
expect((0, get_each_1.getEach)(new Date("2021-05-05"), new Date("2021-08-07"), "month")).toStrictEqual([
|
|
13
|
+
new Date("2021-05-01T00:00:00Z"),
|
|
14
|
+
new Date("2021-06-01T00:00:00Z"),
|
|
15
|
+
new Date("2021-07-01T00:00:00Z"),
|
|
16
|
+
new Date("2021-08-01T00:00:00Z"),
|
|
27
17
|
]);
|
|
28
18
|
});
|
|
29
19
|
test("getEach year", () => {
|
|
30
|
-
expect((0, get_each_1.getEach)("2015-05-05", "2020-05-07", "year")).toStrictEqual([
|
|
31
|
-
"2015-01-
|
|
32
|
-
"2016-01-
|
|
33
|
-
"2017-01-
|
|
34
|
-
"2018-01-
|
|
35
|
-
"2019-01-
|
|
36
|
-
"2020-01-
|
|
20
|
+
expect((0, get_each_1.getEach)(new Date("2015-05-05"), new Date("2020-05-07"), "year")).toStrictEqual([
|
|
21
|
+
new Date("2015-01-01T00:00:00Z"),
|
|
22
|
+
new Date("2016-01-01T00:00:00Z"),
|
|
23
|
+
new Date("2017-01-01T00:00:00Z"),
|
|
24
|
+
new Date("2018-01-01T00:00:00Z"),
|
|
25
|
+
new Date("2019-01-01T00:00:00Z"),
|
|
26
|
+
new Date("2020-01-01T00:00:00Z"),
|
|
37
27
|
]);
|
|
38
28
|
});
|
|
39
|
-
test("getEach
|
|
40
|
-
expect((0, get_each_1.getEach)("
|
|
41
|
-
});
|
|
42
|
-
test("getEach invalid input throws", () => {
|
|
43
|
-
expect(() => (0, get_each_1.getEach)("2015-05-05", "2014-05-07", "day")).toThrow("start must precede end");
|
|
44
|
-
expect(() => (0, get_each_1.getEach)("2021-06-01", "2021-05-01", "month")).toThrow("start must precede end");
|
|
45
|
-
expect(() => (0, get_each_1.getEach)("2020-01-01", "2019-01-01", "year")).toThrow("start must precede end");
|
|
29
|
+
test("getEach invalid input", () => {
|
|
30
|
+
expect(() => (0, get_each_1.getEach)(new Date("2015-05-05"), new Date("2014-05-07T00:00:00Z"), "day")).toThrow();
|
|
46
31
|
});
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInitialMonths = getInitialMonths;
|
|
4
|
-
const
|
|
4
|
+
const dayjs_utils_1 = require("./dayjs-utils");
|
|
5
5
|
const get_current_year_month_and_date_1 = require("./get-current-year-month-and-date");
|
|
6
6
|
const get_date_month_and_year_1 = require("./get-date-month-and-year");
|
|
7
7
|
function getInitialMonths(numberOfMonths, startDate) {
|
|
8
8
|
const firstMonth = startDate ? (0, get_date_month_and_year_1.getDateMonthAndYear)(startDate) : (0, get_current_year_month_and_date_1.getCurrentYearMonthAndDate)();
|
|
9
|
+
let prevMonthDate = firstMonth.date;
|
|
9
10
|
let months = [firstMonth];
|
|
10
11
|
if (numberOfMonths > 1) {
|
|
11
12
|
months = Array.from(Array(numberOfMonths - 1).keys()).reduce((m) => {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
prevMonthDate = (0, dayjs_utils_1.dayjsEnWithTz)(m[m.length - 1].date)
|
|
14
|
+
.add(1, "month")
|
|
15
|
+
.toDate();
|
|
16
|
+
return m.concat([(0, get_date_month_and_year_1.getDateMonthAndYear)(prevMonthDate)]);
|
|
14
17
|
}, months);
|
|
15
18
|
}
|
|
16
19
|
return months;
|
package/utils/get-months.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMonths = getMonths;
|
|
4
4
|
const create_date_string_1 = require("./create-date-string");
|
|
5
|
-
const date_string_1 = require("./date-string");
|
|
6
5
|
const dayjs_utils_1 = require("./dayjs-utils");
|
|
7
6
|
const get_each_1 = require("./get-each");
|
|
8
7
|
function getMonths({ year, monthLabelFormat = (date) => (0, dayjs_utils_1.dayjsEnWithTz)(date).format("MMMM"), }) {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const date = new Date((0, create_date_string_1.createDateString)(year, 0));
|
|
9
|
+
const yearStart = (0, dayjs_utils_1.dayjsEnWithTz)(date).startOf("year").toDate();
|
|
10
|
+
const yearEnd = (0, dayjs_utils_1.dayjsEnWithTz)(date).endOf("year").toDate();
|
|
11
|
+
return (0, get_each_1.getEach)(yearStart, yearEnd, "month").map((d) => ({
|
|
12
|
+
date: d,
|
|
13
|
+
monthLabel: monthLabelFormat(d),
|
|
14
|
+
}));
|
|
15
15
|
}
|