@zag-js/date-utils 0.1.1 → 0.1.3
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/dist/chunk-5HGHDJ3L.mjs +14 -0
- package/dist/chunk-AMZ7CJ5F.mjs +18 -0
- package/dist/chunk-CAYCTIEJ.mjs +29 -0
- package/dist/chunk-G4VVKINZ.mjs +14 -0
- package/dist/chunk-KFJ757ZA.mjs +32 -0
- package/dist/chunk-KLHRN7WS.mjs +20 -0
- package/dist/chunk-KN3YMOSL.mjs +8 -0
- package/dist/chunk-LGEGBP3O.mjs +20 -0
- package/dist/{chunk-NXMEZINO.mjs → chunk-LQAXQPWP.mjs} +4 -7
- package/dist/chunk-ODG5YF5H.mjs +21 -0
- package/dist/chunk-SI75FOJ2.mjs +11 -0
- package/dist/chunk-UHOBXAHP.mjs +17 -0
- package/dist/conversion.d.ts +5 -0
- package/dist/conversion.js +41 -0
- package/dist/conversion.mjs +6 -0
- package/dist/format-selected-date.d.ts +1 -2
- package/dist/format-selected-date.js +14 -14
- package/dist/format-selected-date.mjs +3 -2
- package/dist/format-visible-range.d.ts +1 -2
- package/dist/format-visible-range.js +29 -50
- package/dist/format-visible-range.mjs +4 -3
- package/dist/get-day-formatter.d.ts +5 -0
- package/dist/{placeholder.js → get-day-formatter.js} +22 -21
- package/dist/get-day-formatter.mjs +7 -0
- package/dist/get-decade-range.d.ts +3 -0
- package/dist/get-decade-range.js +38 -0
- package/dist/get-decade-range.mjs +6 -0
- package/dist/get-end-of-week.d.ts +5 -0
- package/dist/{segment-constants.js → get-end-of-week.js} +17 -32
- package/dist/get-end-of-week.mjs +11 -0
- package/dist/get-era-format.d.ts +5 -0
- package/dist/get-era-format.js +32 -0
- package/dist/get-era-format.mjs +6 -0
- package/dist/get-month-days.d.ts +6 -0
- package/dist/{get-month-dates.js → get-month-days.js} +26 -27
- package/dist/get-month-days.mjs +9 -0
- package/dist/get-month-formatter.d.ts +5 -0
- package/dist/{get-formatter.js → get-month-formatter.js} +14 -26
- package/dist/get-month-formatter.mjs +7 -0
- package/dist/get-month-names.d.ts +3 -0
- package/dist/get-month-names.js +38 -0
- package/dist/get-month-names.mjs +6 -0
- package/dist/get-start-of-week.d.ts +5 -0
- package/dist/get-start-of-week.js +35 -0
- package/dist/get-start-of-week.mjs +6 -0
- package/dist/get-week-days.d.ts +10 -0
- package/dist/get-week-days.js +62 -0
- package/dist/get-week-days.mjs +8 -0
- package/dist/get-weekday-formats.d.ts +10 -0
- package/dist/get-weekday-formats.js +44 -0
- package/dist/get-weekday-formats.mjs +6 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +148 -311
- package/dist/index.mjs +36 -41
- package/dist/types.d.ts +1 -2
- package/package.json +2 -2
- package/dist/chunk-55BYHK5B.mjs +0 -31
- package/dist/chunk-DZM5JUL2.mjs +0 -22
- package/dist/chunk-ETRHBIGD.mjs +0 -66
- package/dist/chunk-GLQDJRSE.mjs +0 -31
- package/dist/chunk-JZVHAOWX.mjs +0 -35
- package/dist/chunk-MGRIF22W.mjs +0 -18
- package/dist/chunk-SQCHVCXH.mjs +0 -42
- package/dist/chunk-TSOWYV6W.mjs +0 -34
- package/dist/chunk-U6WRBS5P.mjs +0 -77
- package/dist/get-formatter.d.ts +0 -8
- package/dist/get-formatter.mjs +0 -8
- package/dist/get-month-dates.d.ts +0 -5
- package/dist/get-month-dates.mjs +0 -7
- package/dist/get-week-dates.d.ts +0 -7
- package/dist/get-week-dates.js +0 -60
- package/dist/get-week-dates.mjs +0 -8
- package/dist/placeholder.d.ts +0 -7
- package/dist/placeholder.mjs +0 -8
- package/dist/segment-constants.d.ts +0 -27
- package/dist/segment-constants.mjs +0 -10
- package/dist/segment-limit.d.ts +0 -10
- package/dist/segment-limit.js +0 -101
- package/dist/segment-limit.mjs +0 -6
- package/dist/segment-mutation.d.ts +0 -7
- package/dist/segment-mutation.js +0 -91
- package/dist/segment-mutation.mjs +0 -8
- package/dist/segment-parts.d.ts +0 -27
- package/dist/segment-parts.js +0 -159
- package/dist/segment-parts.mjs +0 -11
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-ETRHBIGD.mjs";
|
|
2
|
+
getWeekDays
|
|
3
|
+
} from "./chunk-AMZ7CJ5F.mjs";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./chunk-SQCHVCXH.mjs";
|
|
9
|
-
import {
|
|
10
|
-
getSegmentLimits
|
|
11
|
-
} from "./chunk-U6WRBS5P.mjs";
|
|
12
|
-
import {
|
|
13
|
-
getMonthDates
|
|
14
|
-
} from "./chunk-MGRIF22W.mjs";
|
|
15
|
-
import {
|
|
16
|
-
getDatesInWeek,
|
|
17
|
-
getWeekDates
|
|
18
|
-
} from "./chunk-JZVHAOWX.mjs";
|
|
5
|
+
getWeekdayFormats
|
|
6
|
+
} from "./chunk-KLHRN7WS.mjs";
|
|
19
7
|
import {
|
|
20
8
|
getYearsRange
|
|
21
9
|
} from "./chunk-TTJVXKJY.mjs";
|
|
@@ -41,14 +29,16 @@ import {
|
|
|
41
29
|
getSectionStart
|
|
42
30
|
} from "./chunk-VTFZA34K.mjs";
|
|
43
31
|
import {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} from "./chunk-DZM5JUL2.mjs";
|
|
32
|
+
getDecadeRange
|
|
33
|
+
} from "./chunk-G4VVKINZ.mjs";
|
|
47
34
|
import {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
getDaysInWeek,
|
|
36
|
+
getMonthDays
|
|
37
|
+
} from "./chunk-KFJ757ZA.mjs";
|
|
38
|
+
import {
|
|
39
|
+
getMonthNames
|
|
40
|
+
} from "./chunk-5HGHDJ3L.mjs";
|
|
41
|
+
import "./chunk-SI75FOJ2.mjs";
|
|
52
42
|
import {
|
|
53
43
|
alignDate,
|
|
54
44
|
alignStartDate
|
|
@@ -70,23 +60,30 @@ import {
|
|
|
70
60
|
constrainStart,
|
|
71
61
|
constrainValue
|
|
72
62
|
} from "./chunk-MGPXEJO4.mjs";
|
|
63
|
+
import {
|
|
64
|
+
parseDateString
|
|
65
|
+
} from "./chunk-UHOBXAHP.mjs";
|
|
73
66
|
import {
|
|
74
67
|
getEndDate,
|
|
75
68
|
getUnitDuration
|
|
76
69
|
} from "./chunk-ZSLC7OI2.mjs";
|
|
77
70
|
import {
|
|
78
71
|
formatSelectedDate
|
|
79
|
-
} from "./chunk-
|
|
80
|
-
import {
|
|
81
|
-
formatVisibleRange
|
|
82
|
-
} from "./chunk-GLQDJRSE.mjs";
|
|
72
|
+
} from "./chunk-LQAXQPWP.mjs";
|
|
83
73
|
import {
|
|
84
74
|
formatRange
|
|
85
75
|
} from "./chunk-HKHGJ6WS.mjs";
|
|
86
|
-
import
|
|
76
|
+
import {
|
|
77
|
+
formatVisibleRange
|
|
78
|
+
} from "./chunk-CAYCTIEJ.mjs";
|
|
79
|
+
import {
|
|
80
|
+
getMonthFormatter
|
|
81
|
+
} from "./chunk-LGEGBP3O.mjs";
|
|
82
|
+
import {
|
|
83
|
+
getDayFormatter
|
|
84
|
+
} from "./chunk-ODG5YF5H.mjs";
|
|
85
|
+
import "./chunk-KN3YMOSL.mjs";
|
|
87
86
|
export {
|
|
88
|
-
SEGMENT_PAGE_STEP,
|
|
89
|
-
addSegment,
|
|
90
87
|
alignCenter,
|
|
91
88
|
alignDate,
|
|
92
89
|
alignEnd,
|
|
@@ -94,15 +91,17 @@ export {
|
|
|
94
91
|
alignStartDate,
|
|
95
92
|
constrainStart,
|
|
96
93
|
constrainValue,
|
|
97
|
-
createPlaceholderDate,
|
|
98
94
|
formatRange,
|
|
99
95
|
formatSelectedDate,
|
|
100
96
|
formatVisibleRange,
|
|
101
97
|
getAdjustedDateFn,
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
getDayFormatter,
|
|
99
|
+
getDaysInWeek,
|
|
100
|
+
getDecadeRange,
|
|
104
101
|
getEndDate,
|
|
105
|
-
|
|
102
|
+
getMonthDays,
|
|
103
|
+
getMonthFormatter,
|
|
104
|
+
getMonthNames,
|
|
106
105
|
getNextDay,
|
|
107
106
|
getNextPage,
|
|
108
107
|
getNextRow,
|
|
@@ -114,13 +113,10 @@ export {
|
|
|
114
113
|
getPreviousSection,
|
|
115
114
|
getSectionEnd,
|
|
116
115
|
getSectionStart,
|
|
117
|
-
getSegmentLimits,
|
|
118
|
-
getSegmentPageStep,
|
|
119
|
-
getSegments,
|
|
120
116
|
getTodayDate,
|
|
121
|
-
getTodayPlaceholderDate,
|
|
122
117
|
getUnitDuration,
|
|
123
|
-
|
|
118
|
+
getWeekDays,
|
|
119
|
+
getWeekdayFormats,
|
|
124
120
|
getYearsRange,
|
|
125
121
|
isDateDisabled,
|
|
126
122
|
isDateEqual,
|
|
@@ -129,11 +125,10 @@ export {
|
|
|
129
125
|
isDateUnavailable,
|
|
130
126
|
isNextVisibleRangeInvalid,
|
|
131
127
|
isPreviousVisibleRangeInvalid,
|
|
132
|
-
isSegmentEditable,
|
|
133
128
|
isTodayDate,
|
|
129
|
+
parseDateString,
|
|
134
130
|
setCalendar,
|
|
135
131
|
setDate,
|
|
136
132
|
setMonth,
|
|
137
|
-
setSegment,
|
|
138
133
|
setYear
|
|
139
134
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ type DateAdjustFn = (options: {
|
|
|
16
16
|
focusedDate: CalendarDate;
|
|
17
17
|
endDate: CalendarDate;
|
|
18
18
|
};
|
|
19
|
-
type DateSegmentPart = Intl.DateTimeFormatPartTypes;
|
|
20
19
|
type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
21
20
|
|
|
22
|
-
export { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity,
|
|
21
|
+
export { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity, GetFormatterFn, GetPlaceholderFn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/date-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Date utilities for zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"clean-package": "2.2.0",
|
|
31
|
-
"@internationalized/date": "^3.0
|
|
31
|
+
"@internationalized/date": "^3.1.0"
|
|
32
32
|
},
|
|
33
33
|
"module": "dist/index.mjs",
|
|
34
34
|
"types": "dist/index.d.ts",
|
package/dist/chunk-55BYHK5B.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// src/segment-constants.ts
|
|
2
|
-
var EDITABLE_SEGMENTS = {
|
|
3
|
-
year: true,
|
|
4
|
-
month: true,
|
|
5
|
-
day: true,
|
|
6
|
-
hour: true,
|
|
7
|
-
minute: true,
|
|
8
|
-
second: true,
|
|
9
|
-
dayPeriod: true,
|
|
10
|
-
era: true
|
|
11
|
-
};
|
|
12
|
-
var SEGMENT_PAGE_STEP = {
|
|
13
|
-
year: 5,
|
|
14
|
-
month: 2,
|
|
15
|
-
day: 7,
|
|
16
|
-
hour: 2,
|
|
17
|
-
minute: 15,
|
|
18
|
-
second: 15
|
|
19
|
-
};
|
|
20
|
-
function isSegmentEditable(segment) {
|
|
21
|
-
return EDITABLE_SEGMENTS[segment];
|
|
22
|
-
}
|
|
23
|
-
function getSegmentPageStep(segment) {
|
|
24
|
-
return SEGMENT_PAGE_STEP[segment] ?? 1;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
SEGMENT_PAGE_STEP,
|
|
29
|
-
isSegmentEditable,
|
|
30
|
-
getSegmentPageStep
|
|
31
|
-
};
|
package/dist/chunk-DZM5JUL2.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// src/placeholder.ts
|
|
2
|
-
import { now, toCalendarDate } from "@internationalized/date";
|
|
3
|
-
function getTodayPlaceholderDate(timeZone) {
|
|
4
|
-
return now(timeZone).set({
|
|
5
|
-
hour: 0,
|
|
6
|
-
minute: 0,
|
|
7
|
-
second: 0,
|
|
8
|
-
millisecond: 0
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
function createPlaceholderDate(granularity, timeZone) {
|
|
12
|
-
let date = getTodayPlaceholderDate(timeZone);
|
|
13
|
-
if (granularity === "year" || granularity === "month" || granularity === "day") {
|
|
14
|
-
return toCalendarDate(date);
|
|
15
|
-
}
|
|
16
|
-
return date;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
getTodayPlaceholderDate,
|
|
21
|
-
createPlaceholderDate
|
|
22
|
-
};
|
package/dist/chunk-ETRHBIGD.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// src/segment-mutation.ts
|
|
2
|
-
function addSegment(date, part, amount, options) {
|
|
3
|
-
switch (part) {
|
|
4
|
-
case "era":
|
|
5
|
-
case "year":
|
|
6
|
-
case "month":
|
|
7
|
-
case "day":
|
|
8
|
-
return date.cycle(part, amount, { round: part === "year" });
|
|
9
|
-
}
|
|
10
|
-
if ("hour" in date) {
|
|
11
|
-
switch (part) {
|
|
12
|
-
case "dayPeriod": {
|
|
13
|
-
let hours = date.hour;
|
|
14
|
-
let isPM = hours >= 12;
|
|
15
|
-
return date.set({ hour: isPM ? hours - 12 : hours + 12 });
|
|
16
|
-
}
|
|
17
|
-
case "hour":
|
|
18
|
-
case "minute":
|
|
19
|
-
case "second":
|
|
20
|
-
return date.cycle(part, amount, {
|
|
21
|
-
round: part !== "hour",
|
|
22
|
-
hourCycle: options?.hour12 ? 12 : 24
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return date;
|
|
27
|
-
}
|
|
28
|
-
function setSegment(date, part, value, options) {
|
|
29
|
-
switch (part) {
|
|
30
|
-
case "day":
|
|
31
|
-
case "month":
|
|
32
|
-
case "year":
|
|
33
|
-
case "era":
|
|
34
|
-
return date.set({ [part]: value });
|
|
35
|
-
}
|
|
36
|
-
if ("hour" in date) {
|
|
37
|
-
switch (part) {
|
|
38
|
-
case "dayPeriod": {
|
|
39
|
-
let hours = date.hour;
|
|
40
|
-
let wasPM = hours >= 12;
|
|
41
|
-
let isPM = value >= 12;
|
|
42
|
-
return isPM === wasPM ? date : date.set({ hour: wasPM ? hours - 12 : hours + 12 });
|
|
43
|
-
}
|
|
44
|
-
case "hour":
|
|
45
|
-
if (options?.hour12) {
|
|
46
|
-
let hours = date.hour;
|
|
47
|
-
let wasPM = hours >= 12;
|
|
48
|
-
if (!wasPM && value === 12) {
|
|
49
|
-
value = 0;
|
|
50
|
-
}
|
|
51
|
-
if (wasPM && value < 12) {
|
|
52
|
-
value += 12;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
case "minute":
|
|
56
|
-
case "second":
|
|
57
|
-
return date.set({ [part]: value });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return date;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
addSegment,
|
|
65
|
-
setSegment
|
|
66
|
-
};
|
package/dist/chunk-GLQDJRSE.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatRange
|
|
3
|
-
} from "./chunk-HKHGJ6WS.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getDateFormatter,
|
|
6
|
-
getMonthFormatter
|
|
7
|
-
} from "./chunk-TSOWYV6W.mjs";
|
|
8
|
-
|
|
9
|
-
// src/format-visible-range.ts
|
|
10
|
-
import { endOfMonth, isSameDay, startOfMonth } from "@internationalized/date";
|
|
11
|
-
function formatVisibleRange(startDate, endDate, getFormatter, isAria, timeZone) {
|
|
12
|
-
if (!startDate)
|
|
13
|
-
return "";
|
|
14
|
-
let start = startDate;
|
|
15
|
-
let end = endDate ?? startDate;
|
|
16
|
-
let monthFormatter = getMonthFormatter(start, end, getFormatter, timeZone);
|
|
17
|
-
let dateFormatter = getDateFormatter(start, end, getFormatter, timeZone);
|
|
18
|
-
if (!isSameDay(start, startOfMonth(start))) {
|
|
19
|
-
return isAria ? formatRange(start, end, dateFormatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone) : dateFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
20
|
-
}
|
|
21
|
-
if (isSameDay(end, endOfMonth(start))) {
|
|
22
|
-
return monthFormatter.format(start.toDate(timeZone));
|
|
23
|
-
}
|
|
24
|
-
if (isSameDay(end, endOfMonth(end))) {
|
|
25
|
-
return isAria ? formatRange(start, end, monthFormatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone) : monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
formatVisibleRange
|
|
31
|
-
};
|
package/dist/chunk-JZVHAOWX.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// src/get-week-dates.ts
|
|
2
|
-
import { getDayOfWeek, isSameDay, startOfWeek } from "@internationalized/date";
|
|
3
|
-
function getDatesInWeek(weekIndex, fromDate, locale) {
|
|
4
|
-
let date = fromDate.add({ weeks: weekIndex });
|
|
5
|
-
let dates = [];
|
|
6
|
-
date = startOfWeek(date, locale);
|
|
7
|
-
let dayOfWeek = getDayOfWeek(date, locale);
|
|
8
|
-
for (let i = 0; i < dayOfWeek; i++) {
|
|
9
|
-
dates.push(null);
|
|
10
|
-
}
|
|
11
|
-
while (dates.length < 7) {
|
|
12
|
-
dates.push(date);
|
|
13
|
-
let nextDate = date.add({ days: 1 });
|
|
14
|
-
if (isSameDay(date, nextDate)) {
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
date = nextDate;
|
|
18
|
-
}
|
|
19
|
-
while (dates.length < 7) {
|
|
20
|
-
dates.push(null);
|
|
21
|
-
}
|
|
22
|
-
return dates;
|
|
23
|
-
}
|
|
24
|
-
function getWeekDates(fromDate, timeZone, locale) {
|
|
25
|
-
let weekStart = startOfWeek(fromDate, locale);
|
|
26
|
-
let weekArr = [...new Array(7).keys()];
|
|
27
|
-
return weekArr.map((index) => {
|
|
28
|
-
return weekStart.add({ days: index }).toDate(timeZone);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
getDatesInWeek,
|
|
34
|
-
getWeekDates
|
|
35
|
-
};
|
package/dist/chunk-MGRIF22W.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getDatesInWeek
|
|
3
|
-
} from "./chunk-JZVHAOWX.mjs";
|
|
4
|
-
|
|
5
|
-
// src/get-month-dates.ts
|
|
6
|
-
import { getWeeksInMonth } from "@internationalized/date";
|
|
7
|
-
function getMonthDates(startDate, duration, locale) {
|
|
8
|
-
let weeksInMonth = getWeeksInMonth(startDate, locale);
|
|
9
|
-
let numOfWeeks = duration.weeks ?? weeksInMonth;
|
|
10
|
-
let weekArr = [...new Array(numOfWeeks).keys()];
|
|
11
|
-
return weekArr.map((index) => {
|
|
12
|
-
return getDatesInWeek(index, startDate, locale);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
getMonthDates
|
|
18
|
-
};
|
package/dist/chunk-SQCHVCXH.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getSegmentLimits
|
|
3
|
-
} from "./chunk-U6WRBS5P.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getTodayPlaceholderDate
|
|
6
|
-
} from "./chunk-DZM5JUL2.mjs";
|
|
7
|
-
import {
|
|
8
|
-
isSegmentEditable
|
|
9
|
-
} from "./chunk-55BYHK5B.mjs";
|
|
10
|
-
|
|
11
|
-
// src/segment-parts.ts
|
|
12
|
-
function getAllSegments(segments) {
|
|
13
|
-
return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
|
|
14
|
-
}
|
|
15
|
-
function getPlaceholder(options) {
|
|
16
|
-
const placeholder = { day: "dd", month: "mm", year: "yyyy" };
|
|
17
|
-
return placeholder[options.field];
|
|
18
|
-
}
|
|
19
|
-
function getSegments(date, validSegments, formatter, timeZone) {
|
|
20
|
-
const dateValue = date || getTodayPlaceholderDate(timeZone);
|
|
21
|
-
const segments = formatter.formatToParts(dateValue.toDate(timeZone));
|
|
22
|
-
return segments.map((segment) => {
|
|
23
|
-
let isEditable = isSegmentEditable(segment.type);
|
|
24
|
-
if (segment.type === "era")
|
|
25
|
-
isEditable = false;
|
|
26
|
-
let isPlaceholder = isSegmentEditable(segment.type) && !validSegments[segment.type];
|
|
27
|
-
let placeholder = isSegmentEditable(segment.type) ? getPlaceholder({ field: segment.type }) : null;
|
|
28
|
-
return {
|
|
29
|
-
type: segment.type,
|
|
30
|
-
text: isPlaceholder ? placeholder : segment.value,
|
|
31
|
-
...getSegmentLimits(dateValue, segment.type, formatter.resolvedOptions()),
|
|
32
|
-
isPlaceholder: !!isPlaceholder,
|
|
33
|
-
placeholder,
|
|
34
|
-
isEditable: !!isEditable
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
getAllSegments,
|
|
41
|
-
getSegments
|
|
42
|
-
};
|
package/dist/chunk-TSOWYV6W.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// src/get-formatter.ts
|
|
2
|
-
function getEraFormat(date) {
|
|
3
|
-
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
4
|
-
}
|
|
5
|
-
function getDateFormatter(startDate, endDate, getDateFormatter2, timeZone) {
|
|
6
|
-
let start = startDate;
|
|
7
|
-
let end = endDate ?? startDate;
|
|
8
|
-
let era = getEraFormat(start) || getEraFormat(end);
|
|
9
|
-
return getDateFormatter2({
|
|
10
|
-
weekday: "long",
|
|
11
|
-
month: "long",
|
|
12
|
-
year: "numeric",
|
|
13
|
-
day: "numeric",
|
|
14
|
-
era,
|
|
15
|
-
timeZone
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function getMonthFormatter(startDate, endDate, getDateFormatter2, timeZone) {
|
|
19
|
-
let start = startDate;
|
|
20
|
-
let end = endDate ?? startDate;
|
|
21
|
-
let era = getEraFormat(start) || getEraFormat(end);
|
|
22
|
-
return getDateFormatter2({
|
|
23
|
-
month: "long",
|
|
24
|
-
year: "numeric",
|
|
25
|
-
era,
|
|
26
|
-
calendar: start?.calendar.identifier,
|
|
27
|
-
timeZone
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
getDateFormatter,
|
|
33
|
-
getMonthFormatter
|
|
34
|
-
};
|
package/dist/chunk-U6WRBS5P.mjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// src/segment-limit.ts
|
|
2
|
-
import { getMinimumDayInMonth, getMinimumMonthInYear } from "@internationalized/date";
|
|
3
|
-
function getSegmentLimits(date, type, options) {
|
|
4
|
-
switch (type) {
|
|
5
|
-
case "era": {
|
|
6
|
-
let eras = date.calendar.getEras();
|
|
7
|
-
return {
|
|
8
|
-
value: eras.indexOf(date.era),
|
|
9
|
-
min: 0,
|
|
10
|
-
max: eras.length - 1
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
case "year":
|
|
14
|
-
return {
|
|
15
|
-
value: date.year,
|
|
16
|
-
min: 1,
|
|
17
|
-
max: date.calendar.getYearsInEra(date)
|
|
18
|
-
};
|
|
19
|
-
case "month":
|
|
20
|
-
return {
|
|
21
|
-
value: date.month,
|
|
22
|
-
min: getMinimumMonthInYear(date),
|
|
23
|
-
max: date.calendar.getMonthsInYear(date)
|
|
24
|
-
};
|
|
25
|
-
case "day":
|
|
26
|
-
return {
|
|
27
|
-
value: date.day,
|
|
28
|
-
min: getMinimumDayInMonth(date),
|
|
29
|
-
max: date.calendar.getDaysInMonth(date)
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if ("hour" in date) {
|
|
33
|
-
switch (type) {
|
|
34
|
-
case "dayPeriod":
|
|
35
|
-
return {
|
|
36
|
-
value: date.hour >= 12 ? 12 : 0,
|
|
37
|
-
min: 0,
|
|
38
|
-
max: 12
|
|
39
|
-
};
|
|
40
|
-
case "hour":
|
|
41
|
-
if (options?.hour12) {
|
|
42
|
-
let isPM = date.hour >= 12;
|
|
43
|
-
return {
|
|
44
|
-
value: date.hour,
|
|
45
|
-
min: isPM ? 12 : 0,
|
|
46
|
-
max: isPM ? 23 : 11
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
value: date.hour,
|
|
51
|
-
min: 0,
|
|
52
|
-
max: 23
|
|
53
|
-
};
|
|
54
|
-
case "minute":
|
|
55
|
-
return {
|
|
56
|
-
value: date.minute,
|
|
57
|
-
min: 0,
|
|
58
|
-
max: 59
|
|
59
|
-
};
|
|
60
|
-
case "second":
|
|
61
|
-
return {
|
|
62
|
-
value: date.second,
|
|
63
|
-
min: 0,
|
|
64
|
-
max: 59
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
value: -1,
|
|
70
|
-
min: -1,
|
|
71
|
-
max: -1
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
getSegmentLimits
|
|
77
|
-
};
|
package/dist/get-formatter.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
-
import { CalendarDate } from '@internationalized/date';
|
|
3
|
-
import { GetFormatterFn } from './types.js';
|
|
4
|
-
|
|
5
|
-
declare function getDateFormatter(startDate: CalendarDate, endDate: CalendarDate | null, getDateFormatter: GetFormatterFn, timeZone: string): _internationalized_date.DateFormatter;
|
|
6
|
-
declare function getMonthFormatter(startDate: CalendarDate, endDate: CalendarDate | null, getDateFormatter: GetFormatterFn, timeZone: string): _internationalized_date.DateFormatter;
|
|
7
|
-
|
|
8
|
-
export { getDateFormatter, getMonthFormatter };
|
package/dist/get-formatter.mjs
DELETED
package/dist/get-month-dates.mjs
DELETED
package/dist/get-week-dates.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CalendarDate } from '@internationalized/date';
|
|
2
|
-
|
|
3
|
-
type DatesInWeek = (CalendarDate | null)[];
|
|
4
|
-
declare function getDatesInWeek(weekIndex: number, fromDate: CalendarDate, locale: string): (CalendarDate | null)[];
|
|
5
|
-
declare function getWeekDates(fromDate: CalendarDate, timeZone: string, locale: string): Date[];
|
|
6
|
-
|
|
7
|
-
export { DatesInWeek, getDatesInWeek, getWeekDates };
|
package/dist/get-week-dates.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/get-week-dates.ts
|
|
21
|
-
var get_week_dates_exports = {};
|
|
22
|
-
__export(get_week_dates_exports, {
|
|
23
|
-
getDatesInWeek: () => getDatesInWeek,
|
|
24
|
-
getWeekDates: () => getWeekDates
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(get_week_dates_exports);
|
|
27
|
-
var import_date = require("@internationalized/date");
|
|
28
|
-
function getDatesInWeek(weekIndex, fromDate, locale) {
|
|
29
|
-
let date = fromDate.add({ weeks: weekIndex });
|
|
30
|
-
let dates = [];
|
|
31
|
-
date = (0, import_date.startOfWeek)(date, locale);
|
|
32
|
-
let dayOfWeek = (0, import_date.getDayOfWeek)(date, locale);
|
|
33
|
-
for (let i = 0; i < dayOfWeek; i++) {
|
|
34
|
-
dates.push(null);
|
|
35
|
-
}
|
|
36
|
-
while (dates.length < 7) {
|
|
37
|
-
dates.push(date);
|
|
38
|
-
let nextDate = date.add({ days: 1 });
|
|
39
|
-
if ((0, import_date.isSameDay)(date, nextDate)) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
date = nextDate;
|
|
43
|
-
}
|
|
44
|
-
while (dates.length < 7) {
|
|
45
|
-
dates.push(null);
|
|
46
|
-
}
|
|
47
|
-
return dates;
|
|
48
|
-
}
|
|
49
|
-
function getWeekDates(fromDate, timeZone, locale) {
|
|
50
|
-
let weekStart = (0, import_date.startOfWeek)(fromDate, locale);
|
|
51
|
-
let weekArr = [...new Array(7).keys()];
|
|
52
|
-
return weekArr.map((index) => {
|
|
53
|
-
return weekStart.add({ days: index }).toDate(timeZone);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
-
0 && (module.exports = {
|
|
58
|
-
getDatesInWeek,
|
|
59
|
-
getWeekDates
|
|
60
|
-
});
|
package/dist/get-week-dates.mjs
DELETED
package/dist/placeholder.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
-
import { DateGranularity } from './types.js';
|
|
3
|
-
|
|
4
|
-
declare function getTodayPlaceholderDate(timeZone: string): _internationalized_date.ZonedDateTime;
|
|
5
|
-
declare function createPlaceholderDate(granularity: DateGranularity, timeZone: string): _internationalized_date.CalendarDate | _internationalized_date.ZonedDateTime;
|
|
6
|
-
|
|
7
|
-
export { createPlaceholderDate, getTodayPlaceholderDate };
|
package/dist/placeholder.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { DateSegmentPart } from './types.js';
|
|
2
|
-
import '@internationalized/date';
|
|
3
|
-
|
|
4
|
-
declare const EDITABLE_SEGMENTS: {
|
|
5
|
-
year: boolean;
|
|
6
|
-
month: boolean;
|
|
7
|
-
day: boolean;
|
|
8
|
-
hour: boolean;
|
|
9
|
-
minute: boolean;
|
|
10
|
-
second: boolean;
|
|
11
|
-
dayPeriod: boolean;
|
|
12
|
-
era: boolean;
|
|
13
|
-
};
|
|
14
|
-
type DateSegments = Partial<typeof EDITABLE_SEGMENTS>;
|
|
15
|
-
type DateSegment = keyof DateSegments;
|
|
16
|
-
declare const SEGMENT_PAGE_STEP: {
|
|
17
|
-
year: number;
|
|
18
|
-
month: number;
|
|
19
|
-
day: number;
|
|
20
|
-
hour: number;
|
|
21
|
-
minute: number;
|
|
22
|
-
second: number;
|
|
23
|
-
};
|
|
24
|
-
declare function isSegmentEditable(segment: DateSegmentPart): any;
|
|
25
|
-
declare function getSegmentPageStep(segment: DateSegmentPart): any;
|
|
26
|
-
|
|
27
|
-
export { DateSegment, DateSegments, SEGMENT_PAGE_STEP, getSegmentPageStep, isSegmentEditable };
|