@zag-js/date-utils 1.34.0 → 1.35.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/dist/align.d.mts +8 -0
- package/dist/align.d.ts +8 -0
- package/dist/align.js +52 -0
- package/dist/align.mjs +26 -0
- package/dist/assertion.d.mts +10 -0
- package/dist/assertion.d.ts +10 -0
- package/dist/assertion.js +58 -0
- package/dist/assertion.mjs +29 -0
- package/dist/constrain.d.mts +9 -0
- package/dist/constrain.d.ts +9 -0
- package/dist/constrain.js +109 -0
- package/dist/constrain.mjs +87 -0
- package/dist/date-month.d.mts +23 -0
- package/dist/date-month.d.ts +23 -0
- package/dist/date-month.js +131 -0
- package/dist/date-month.mjs +105 -0
- package/dist/date-year.d.mts +14 -0
- package/dist/date-year.d.ts +14 -0
- package/dist/date-year.js +72 -0
- package/dist/date-year.mjs +44 -0
- package/dist/duration.d.mts +13 -0
- package/dist/duration.d.ts +13 -0
- package/dist/duration.js +42 -0
- package/dist/duration.mjs +16 -0
- package/dist/format.d.mts +8 -0
- package/dist/format.d.ts +8 -0
- package/dist/format.js +83 -0
- package/dist/format.mjs +56 -0
- package/dist/formatter.d.mts +6 -0
- package/dist/formatter.d.ts +6 -0
- package/dist/formatter.js +55 -0
- package/dist/formatter.mjs +29 -0
- package/dist/get-era-format.d.mts +6 -0
- package/dist/get-era-format.d.ts +6 -0
- package/dist/get-era-format.js +37 -0
- package/dist/get-era-format.mjs +12 -0
- package/dist/index.d.mts +14 -103
- package/dist/index.d.ts +14 -103
- package/dist/index.js +46 -637
- package/dist/index.mjs +13 -591
- package/dist/mutation.d.mts +10 -0
- package/dist/mutation.d.ts +10 -0
- package/dist/mutation.js +62 -0
- package/dist/mutation.mjs +39 -0
- package/dist/pagination.d.mts +21 -0
- package/dist/pagination.d.ts +21 -0
- package/dist/pagination.js +220 -0
- package/dist/pagination.mjs +187 -0
- package/dist/parse-date.d.mts +6 -0
- package/dist/parse-date.d.ts +6 -0
- package/dist/parse-date.js +79 -0
- package/dist/parse-date.mjs +54 -0
- package/dist/preset.d.mts +6 -0
- package/dist/preset.d.ts +6 -0
- package/dist/preset.js +66 -0
- package/dist/preset.mjs +50 -0
- package/dist/types.d.mts +23 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/mutation.ts
|
|
2
|
+
import {
|
|
3
|
+
getLocalTimeZone,
|
|
4
|
+
toCalendar,
|
|
5
|
+
toCalendarDateTime,
|
|
6
|
+
today
|
|
7
|
+
} from "@internationalized/date";
|
|
8
|
+
import { constrainValue } from "./constrain.mjs";
|
|
9
|
+
function getTodayDate(timeZone, calendar) {
|
|
10
|
+
const tod = today(timeZone ?? getLocalTimeZone());
|
|
11
|
+
if (calendar) return toCalendar(tod, calendar);
|
|
12
|
+
return tod;
|
|
13
|
+
}
|
|
14
|
+
function setCalendar(date, calendar) {
|
|
15
|
+
return toCalendar(toCalendarDateTime(date), calendar);
|
|
16
|
+
}
|
|
17
|
+
function setDate(date, startDate, isDateUnavailable, locale, minValue, maxValue) {
|
|
18
|
+
let result;
|
|
19
|
+
result = constrainValue(date, minValue, maxValue);
|
|
20
|
+
result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable) {
|
|
24
|
+
if (!isDateUnavailable) {
|
|
25
|
+
return date;
|
|
26
|
+
}
|
|
27
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable(date, locale)) {
|
|
28
|
+
date = date.subtract({ days: 1 });
|
|
29
|
+
}
|
|
30
|
+
if (date.compare(minValue) >= 0) {
|
|
31
|
+
return date;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
getPreviousAvailableDate,
|
|
36
|
+
getTodayDate,
|
|
37
|
+
setCalendar,
|
|
38
|
+
setDate
|
|
39
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DateDuration } from '@internationalized/date';
|
|
2
|
+
import { DateValue } from './types.mjs';
|
|
3
|
+
|
|
4
|
+
interface AdjustDateParams {
|
|
5
|
+
startDate: DateValue;
|
|
6
|
+
focusedDate: DateValue;
|
|
7
|
+
}
|
|
8
|
+
interface AdjustDateReturn extends AdjustDateParams {
|
|
9
|
+
endDate: DateValue;
|
|
10
|
+
}
|
|
11
|
+
declare function getAdjustedDateFn(visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): (options: AdjustDateParams) => AdjustDateReturn;
|
|
12
|
+
declare function getNextPage(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn;
|
|
13
|
+
declare function getPreviousPage(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn;
|
|
14
|
+
declare function getNextRow(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
15
|
+
declare function getPreviousRow(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
16
|
+
declare function getSectionStart(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
17
|
+
declare function getSectionEnd(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
18
|
+
declare function getNextSection(focusedDate: DateValue, startDate: DateValue, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
19
|
+
declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
20
|
+
|
|
21
|
+
export { type AdjustDateParams, type AdjustDateReturn, getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DateDuration } from '@internationalized/date';
|
|
2
|
+
import { DateValue } from './types.js';
|
|
3
|
+
|
|
4
|
+
interface AdjustDateParams {
|
|
5
|
+
startDate: DateValue;
|
|
6
|
+
focusedDate: DateValue;
|
|
7
|
+
}
|
|
8
|
+
interface AdjustDateReturn extends AdjustDateParams {
|
|
9
|
+
endDate: DateValue;
|
|
10
|
+
}
|
|
11
|
+
declare function getAdjustedDateFn(visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): (options: AdjustDateParams) => AdjustDateReturn;
|
|
12
|
+
declare function getNextPage(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn;
|
|
13
|
+
declare function getPreviousPage(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn;
|
|
14
|
+
declare function getNextRow(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
15
|
+
declare function getPreviousRow(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
16
|
+
declare function getSectionStart(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
17
|
+
declare function getSectionEnd(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
18
|
+
declare function getNextSection(focusedDate: DateValue, startDate: DateValue, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
19
|
+
declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): AdjustDateReturn | undefined;
|
|
20
|
+
|
|
21
|
+
export { type AdjustDateParams, type AdjustDateReturn, getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
|
|
@@ -0,0 +1,220 @@
|
|
|
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/pagination.ts
|
|
21
|
+
var pagination_exports = {};
|
|
22
|
+
__export(pagination_exports, {
|
|
23
|
+
getAdjustedDateFn: () => getAdjustedDateFn,
|
|
24
|
+
getNextPage: () => getNextPage,
|
|
25
|
+
getNextRow: () => getNextRow,
|
|
26
|
+
getNextSection: () => getNextSection,
|
|
27
|
+
getPreviousPage: () => getPreviousPage,
|
|
28
|
+
getPreviousRow: () => getPreviousRow,
|
|
29
|
+
getPreviousSection: () => getPreviousSection,
|
|
30
|
+
getSectionEnd: () => getSectionEnd,
|
|
31
|
+
getSectionStart: () => getSectionStart
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(pagination_exports);
|
|
34
|
+
var import_date = require("@internationalized/date");
|
|
35
|
+
var import_assertion = require("./assertion.cjs");
|
|
36
|
+
var import_constrain = require("./constrain.cjs");
|
|
37
|
+
var import_duration = require("./duration.cjs");
|
|
38
|
+
function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
|
|
39
|
+
return function getDate(options) {
|
|
40
|
+
const { startDate, focusedDate } = options;
|
|
41
|
+
const endDate = (0, import_duration.getEndDate)(startDate, visibleDuration);
|
|
42
|
+
if ((0, import_assertion.isDateOutsideRange)(focusedDate, minValue, maxValue)) {
|
|
43
|
+
return {
|
|
44
|
+
startDate,
|
|
45
|
+
focusedDate: (0, import_constrain.constrainValue)(focusedDate, minValue, maxValue),
|
|
46
|
+
endDate
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
50
|
+
return {
|
|
51
|
+
startDate: (0, import_constrain.alignEnd)(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
52
|
+
focusedDate: (0, import_constrain.constrainValue)(focusedDate, minValue, maxValue),
|
|
53
|
+
endDate
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
57
|
+
return {
|
|
58
|
+
startDate: (0, import_constrain.alignStart)(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
59
|
+
endDate,
|
|
60
|
+
focusedDate: (0, import_constrain.constrainValue)(focusedDate, minValue, maxValue)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
startDate,
|
|
65
|
+
endDate,
|
|
66
|
+
focusedDate: (0, import_constrain.constrainValue)(focusedDate, minValue, maxValue)
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
71
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
72
|
+
const start = startDate.add(visibleDuration);
|
|
73
|
+
return adjust({
|
|
74
|
+
focusedDate: focusedDate.add(visibleDuration),
|
|
75
|
+
startDate: (0, import_constrain.alignStart)(
|
|
76
|
+
(0, import_constrain.constrainStart)(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
77
|
+
visibleDuration,
|
|
78
|
+
locale
|
|
79
|
+
)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
83
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
84
|
+
let start = startDate.subtract(visibleDuration);
|
|
85
|
+
return adjust({
|
|
86
|
+
focusedDate: focusedDate.subtract(visibleDuration),
|
|
87
|
+
startDate: (0, import_constrain.alignStart)(
|
|
88
|
+
(0, import_constrain.constrainStart)(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
89
|
+
visibleDuration,
|
|
90
|
+
locale
|
|
91
|
+
)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
95
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
96
|
+
if (visibleDuration.days) {
|
|
97
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
98
|
+
}
|
|
99
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
100
|
+
return adjust({
|
|
101
|
+
focusedDate: focusedDate.add({ weeks: 1 }),
|
|
102
|
+
startDate
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
107
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
108
|
+
if (visibleDuration.days) {
|
|
109
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
110
|
+
}
|
|
111
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
112
|
+
return adjust({
|
|
113
|
+
focusedDate: focusedDate.subtract({ weeks: 1 }),
|
|
114
|
+
startDate
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
119
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
120
|
+
if (visibleDuration.days) {
|
|
121
|
+
return adjust({
|
|
122
|
+
focusedDate: startDate,
|
|
123
|
+
startDate
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (visibleDuration.weeks) {
|
|
127
|
+
return adjust({
|
|
128
|
+
focusedDate: (0, import_date.startOfWeek)(focusedDate, locale),
|
|
129
|
+
startDate
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
133
|
+
return adjust({
|
|
134
|
+
focusedDate: (0, import_date.startOfMonth)(focusedDate),
|
|
135
|
+
startDate
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
140
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
141
|
+
const endDate = (0, import_duration.getEndDate)(startDate, visibleDuration);
|
|
142
|
+
if (visibleDuration.days) {
|
|
143
|
+
return adjust({
|
|
144
|
+
focusedDate: endDate,
|
|
145
|
+
startDate
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (visibleDuration.weeks) {
|
|
149
|
+
return adjust({
|
|
150
|
+
focusedDate: (0, import_date.endOfWeek)(focusedDate, locale),
|
|
151
|
+
startDate
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
155
|
+
return adjust({
|
|
156
|
+
focusedDate: (0, import_date.endOfMonth)(focusedDate),
|
|
157
|
+
startDate
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
162
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
163
|
+
if (!larger && !visibleDuration.days) {
|
|
164
|
+
return adjust({
|
|
165
|
+
focusedDate: focusedDate.add((0, import_duration.getUnitDuration)(visibleDuration)),
|
|
166
|
+
startDate
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (visibleDuration.days) {
|
|
170
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
171
|
+
}
|
|
172
|
+
if (visibleDuration.weeks) {
|
|
173
|
+
return adjust({
|
|
174
|
+
focusedDate: focusedDate.add({ months: 1 }),
|
|
175
|
+
startDate
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
179
|
+
return adjust({
|
|
180
|
+
focusedDate: focusedDate.add({ years: 1 }),
|
|
181
|
+
startDate
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
186
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
187
|
+
if (!larger && !visibleDuration.days) {
|
|
188
|
+
return adjust({
|
|
189
|
+
focusedDate: focusedDate.subtract((0, import_duration.getUnitDuration)(visibleDuration)),
|
|
190
|
+
startDate
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (visibleDuration.days) {
|
|
194
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
195
|
+
}
|
|
196
|
+
if (visibleDuration.weeks) {
|
|
197
|
+
return adjust({
|
|
198
|
+
focusedDate: focusedDate.subtract({ months: 1 }),
|
|
199
|
+
startDate
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
203
|
+
return adjust({
|
|
204
|
+
focusedDate: focusedDate.subtract({ years: 1 }),
|
|
205
|
+
startDate
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
getAdjustedDateFn,
|
|
212
|
+
getNextPage,
|
|
213
|
+
getNextRow,
|
|
214
|
+
getNextSection,
|
|
215
|
+
getPreviousPage,
|
|
216
|
+
getPreviousRow,
|
|
217
|
+
getPreviousSection,
|
|
218
|
+
getSectionEnd,
|
|
219
|
+
getSectionStart
|
|
220
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// src/pagination.ts
|
|
2
|
+
import { endOfMonth, endOfWeek, startOfMonth, startOfWeek } from "@internationalized/date";
|
|
3
|
+
import { isDateOutsideRange } from "./assertion.mjs";
|
|
4
|
+
import { alignEnd, alignStart, constrainStart, constrainValue } from "./constrain.mjs";
|
|
5
|
+
import { getEndDate, getUnitDuration } from "./duration.mjs";
|
|
6
|
+
function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
|
|
7
|
+
return function getDate(options) {
|
|
8
|
+
const { startDate, focusedDate } = options;
|
|
9
|
+
const endDate = getEndDate(startDate, visibleDuration);
|
|
10
|
+
if (isDateOutsideRange(focusedDate, minValue, maxValue)) {
|
|
11
|
+
return {
|
|
12
|
+
startDate,
|
|
13
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue),
|
|
14
|
+
endDate
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
18
|
+
return {
|
|
19
|
+
startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
20
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue),
|
|
21
|
+
endDate
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
25
|
+
return {
|
|
26
|
+
startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
27
|
+
endDate,
|
|
28
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
startDate,
|
|
33
|
+
endDate,
|
|
34
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
39
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
40
|
+
const start = startDate.add(visibleDuration);
|
|
41
|
+
return adjust({
|
|
42
|
+
focusedDate: focusedDate.add(visibleDuration),
|
|
43
|
+
startDate: alignStart(
|
|
44
|
+
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
45
|
+
visibleDuration,
|
|
46
|
+
locale
|
|
47
|
+
)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
51
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
52
|
+
let start = startDate.subtract(visibleDuration);
|
|
53
|
+
return adjust({
|
|
54
|
+
focusedDate: focusedDate.subtract(visibleDuration),
|
|
55
|
+
startDate: alignStart(
|
|
56
|
+
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
57
|
+
visibleDuration,
|
|
58
|
+
locale
|
|
59
|
+
)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
63
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
64
|
+
if (visibleDuration.days) {
|
|
65
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
66
|
+
}
|
|
67
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
68
|
+
return adjust({
|
|
69
|
+
focusedDate: focusedDate.add({ weeks: 1 }),
|
|
70
|
+
startDate
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
75
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
76
|
+
if (visibleDuration.days) {
|
|
77
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
78
|
+
}
|
|
79
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
80
|
+
return adjust({
|
|
81
|
+
focusedDate: focusedDate.subtract({ weeks: 1 }),
|
|
82
|
+
startDate
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
87
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
88
|
+
if (visibleDuration.days) {
|
|
89
|
+
return adjust({
|
|
90
|
+
focusedDate: startDate,
|
|
91
|
+
startDate
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (visibleDuration.weeks) {
|
|
95
|
+
return adjust({
|
|
96
|
+
focusedDate: startOfWeek(focusedDate, locale),
|
|
97
|
+
startDate
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
101
|
+
return adjust({
|
|
102
|
+
focusedDate: startOfMonth(focusedDate),
|
|
103
|
+
startDate
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
108
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
109
|
+
const endDate = getEndDate(startDate, visibleDuration);
|
|
110
|
+
if (visibleDuration.days) {
|
|
111
|
+
return adjust({
|
|
112
|
+
focusedDate: endDate,
|
|
113
|
+
startDate
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (visibleDuration.weeks) {
|
|
117
|
+
return adjust({
|
|
118
|
+
focusedDate: endOfWeek(focusedDate, locale),
|
|
119
|
+
startDate
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
123
|
+
return adjust({
|
|
124
|
+
focusedDate: endOfMonth(focusedDate),
|
|
125
|
+
startDate
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
130
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
131
|
+
if (!larger && !visibleDuration.days) {
|
|
132
|
+
return adjust({
|
|
133
|
+
focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
|
|
134
|
+
startDate
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (visibleDuration.days) {
|
|
138
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
139
|
+
}
|
|
140
|
+
if (visibleDuration.weeks) {
|
|
141
|
+
return adjust({
|
|
142
|
+
focusedDate: focusedDate.add({ months: 1 }),
|
|
143
|
+
startDate
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
147
|
+
return adjust({
|
|
148
|
+
focusedDate: focusedDate.add({ years: 1 }),
|
|
149
|
+
startDate
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
154
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
155
|
+
if (!larger && !visibleDuration.days) {
|
|
156
|
+
return adjust({
|
|
157
|
+
focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
|
|
158
|
+
startDate
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (visibleDuration.days) {
|
|
162
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
163
|
+
}
|
|
164
|
+
if (visibleDuration.weeks) {
|
|
165
|
+
return adjust({
|
|
166
|
+
focusedDate: focusedDate.subtract({ months: 1 }),
|
|
167
|
+
startDate
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
171
|
+
return adjust({
|
|
172
|
+
focusedDate: focusedDate.subtract({ years: 1 }),
|
|
173
|
+
startDate
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
getAdjustedDateFn,
|
|
179
|
+
getNextPage,
|
|
180
|
+
getNextRow,
|
|
181
|
+
getNextSection,
|
|
182
|
+
getPreviousPage,
|
|
183
|
+
getPreviousRow,
|
|
184
|
+
getPreviousSection,
|
|
185
|
+
getSectionEnd,
|
|
186
|
+
getSectionStart
|
|
187
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
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/parse-date.ts
|
|
21
|
+
var parse_date_exports = {};
|
|
22
|
+
__export(parse_date_exports, {
|
|
23
|
+
parseDateString: () => parseDateString
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(parse_date_exports);
|
|
26
|
+
var import_date = require("@internationalized/date");
|
|
27
|
+
var import_date_year = require("./date-year.cjs");
|
|
28
|
+
var isValidYear = (year) => year != null && year.length === 4;
|
|
29
|
+
var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
30
|
+
var isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
31
|
+
function parseDateString(date, locale, timeZone) {
|
|
32
|
+
const regex = createRegex(locale, timeZone);
|
|
33
|
+
let { year, month, day } = extract(regex, date) ?? {};
|
|
34
|
+
const hasMatch = year != null || month != null || day != null;
|
|
35
|
+
if (hasMatch) {
|
|
36
|
+
const curr = /* @__PURE__ */ new Date();
|
|
37
|
+
year || (year = curr.getFullYear().toString());
|
|
38
|
+
month || (month = (curr.getMonth() + 1).toString());
|
|
39
|
+
day || (day = curr.getDate().toString());
|
|
40
|
+
}
|
|
41
|
+
if (!isValidYear(year)) {
|
|
42
|
+
year = (0, import_date_year.normalizeYear)(year);
|
|
43
|
+
}
|
|
44
|
+
if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) {
|
|
45
|
+
return new import_date.CalendarDate(+year, +month, +day);
|
|
46
|
+
}
|
|
47
|
+
const time = Date.parse(date);
|
|
48
|
+
if (!isNaN(time)) {
|
|
49
|
+
const date2 = new Date(time);
|
|
50
|
+
return new import_date.CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createRegex(locale, timeZone) {
|
|
54
|
+
const formatter = new import_date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
55
|
+
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
56
|
+
return parts.map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
|
|
57
|
+
}
|
|
58
|
+
function extract(pattern, str) {
|
|
59
|
+
const matches = str.match(pattern);
|
|
60
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
61
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
62
|
+
if (!groupMatches || groupMatches.length <= 0) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return group.match(/<(.+)>/)?.[1];
|
|
66
|
+
}).reduce((acc, curr, index) => {
|
|
67
|
+
if (!curr) return acc;
|
|
68
|
+
if (matches && matches.length > index) {
|
|
69
|
+
acc[curr] = matches[index + 1];
|
|
70
|
+
} else {
|
|
71
|
+
acc[curr] = null;
|
|
72
|
+
}
|
|
73
|
+
return acc;
|
|
74
|
+
}, {});
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
parseDateString
|
|
79
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/parse-date.ts
|
|
2
|
+
import { CalendarDate, DateFormatter } from "@internationalized/date";
|
|
3
|
+
import { normalizeYear } from "./date-year.mjs";
|
|
4
|
+
var isValidYear = (year) => year != null && year.length === 4;
|
|
5
|
+
var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
6
|
+
var isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
7
|
+
function parseDateString(date, locale, timeZone) {
|
|
8
|
+
const regex = createRegex(locale, timeZone);
|
|
9
|
+
let { year, month, day } = extract(regex, date) ?? {};
|
|
10
|
+
const hasMatch = year != null || month != null || day != null;
|
|
11
|
+
if (hasMatch) {
|
|
12
|
+
const curr = /* @__PURE__ */ new Date();
|
|
13
|
+
year || (year = curr.getFullYear().toString());
|
|
14
|
+
month || (month = (curr.getMonth() + 1).toString());
|
|
15
|
+
day || (day = curr.getDate().toString());
|
|
16
|
+
}
|
|
17
|
+
if (!isValidYear(year)) {
|
|
18
|
+
year = normalizeYear(year);
|
|
19
|
+
}
|
|
20
|
+
if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) {
|
|
21
|
+
return new CalendarDate(+year, +month, +day);
|
|
22
|
+
}
|
|
23
|
+
const time = Date.parse(date);
|
|
24
|
+
if (!isNaN(time)) {
|
|
25
|
+
const date2 = new Date(time);
|
|
26
|
+
return new CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function createRegex(locale, timeZone) {
|
|
30
|
+
const formatter = new DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
31
|
+
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
32
|
+
return parts.map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
|
|
33
|
+
}
|
|
34
|
+
function extract(pattern, str) {
|
|
35
|
+
const matches = str.match(pattern);
|
|
36
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
37
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
38
|
+
if (!groupMatches || groupMatches.length <= 0) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return group.match(/<(.+)>/)?.[1];
|
|
42
|
+
}).reduce((acc, curr, index) => {
|
|
43
|
+
if (!curr) return acc;
|
|
44
|
+
if (matches && matches.length > index) {
|
|
45
|
+
acc[curr] = matches[index + 1];
|
|
46
|
+
} else {
|
|
47
|
+
acc[curr] = null;
|
|
48
|
+
}
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
parseDateString
|
|
54
|
+
};
|
package/dist/preset.d.ts
ADDED