@zag-js/date-utils 0.0.0-dev-20230107115230 → 0.0.0-dev-20230107153917
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.ts +4 -4
- package/dist/align.js +20 -24
- package/dist/align.mjs +2 -2
- package/dist/assertion.d.ts +8 -8
- package/dist/assertion.js +15 -16
- package/dist/assertion.mjs +1 -1
- package/dist/chunk-6EJZROXM.mjs +45 -0
- package/dist/{chunk-TCPXGBJP.mjs → chunk-BBE325GQ.mjs} +9 -8
- package/dist/chunk-BUT5IUNZ.mjs +32 -0
- package/dist/{chunk-EXWX3KZT.mjs → chunk-CAV5WKCZ.mjs} +4 -2
- package/dist/chunk-GKU5M6QU.mjs +25 -0
- package/dist/{chunk-XHAL6X5Z.mjs → chunk-HKHGJ6WS.mjs} +3 -3
- package/dist/{chunk-ECAENYV6.mjs → chunk-HUBKWHIN.mjs} +1 -1
- package/dist/{chunk-M4F23P2U.mjs → chunk-JZVHAOWX.mjs} +3 -3
- package/dist/{chunk-2DZ3KIVJ.mjs → chunk-L3YHK2WH.mjs} +1 -1
- package/dist/chunk-MGPXEJO4.mjs +71 -0
- package/dist/chunk-MY373KF2.mjs +198 -0
- package/dist/chunk-URPTPFL3.mjs +31 -0
- package/dist/chunk-ZZPZ2BFS.mjs +52 -0
- package/dist/constrain.d.ts +6 -7
- package/dist/constrain.js +20 -25
- package/dist/constrain.mjs +1 -1
- package/dist/format-range.d.ts +2 -3
- package/dist/format-range.js +3 -3
- package/dist/format-range.mjs +1 -1
- package/dist/format-selected-date.d.ts +3 -3
- package/dist/format-selected-date.js +13 -13
- package/dist/format-selected-date.mjs +3 -4
- package/dist/format-visible-range.d.ts +3 -3
- package/dist/format-visible-range.js +18 -17
- package/dist/format-visible-range.mjs +4 -26
- package/dist/get-formatter.d.ts +4 -3
- package/dist/get-formatter.js +6 -8
- package/dist/get-formatter.mjs +1 -2
- package/dist/get-month-dates.mjs +2 -2
- package/dist/get-week-dates.d.ts +1 -1
- package/dist/get-week-dates.js +2 -2
- package/dist/get-week-dates.mjs +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +284 -181
- package/dist/index.mjs +22 -19
- package/dist/mutation.d.ts +5 -5
- package/dist/mutation.js +16 -43
- package/dist/mutation.mjs +4 -5
- package/dist/pagination.d.ts +29 -10
- package/dist/pagination.js +183 -89
- package/dist/pagination.mjs +3 -2
- package/dist/placeholder.d.ts +1 -1
- package/dist/segment-constants.d.ts +1 -1
- package/dist/segment-limit.d.ts +2 -2
- package/dist/segment-limit.js +1 -1
- package/dist/segment-limit.mjs +1 -1
- package/dist/segment-mutation.d.ts +3 -4
- package/dist/segment-mutation.js +4 -2
- package/dist/segment-mutation.mjs +1 -1
- package/dist/segment-parts.d.ts +2 -2
- package/dist/segment-parts.js +4 -4
- package/dist/segment-parts.mjs +6 -6
- package/dist/types-cbf8b45a.d.ts +35 -0
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-6XKXGQP6.mjs +0 -32
- package/dist/chunk-7JERMWT3.mjs +0 -46
- package/dist/chunk-C4U2N3JC.mjs +0 -65
- package/dist/chunk-DI2YG6VG.mjs +0 -24
- package/dist/chunk-FJMTHABG.mjs +0 -8
- package/dist/chunk-HP2COJGP.mjs +0 -76
- package/dist/chunk-VWVBJ5CB.mjs +0 -110
- package/dist/get-era-format.d.ts +0 -5
- package/dist/get-era-format.js +0 -32
- package/dist/get-era-format.mjs +0 -6
- package/dist/types-9f60d2f1.d.ts +0 -61
package/dist/index.js
CHANGED
|
@@ -27,11 +27,11 @@ __export(src_exports, {
|
|
|
27
27
|
alignEnd: () => alignEnd,
|
|
28
28
|
alignStart: () => alignStart,
|
|
29
29
|
alignStartDate: () => alignStartDate,
|
|
30
|
-
clampDate: () => clampDate,
|
|
31
30
|
constrainStart: () => constrainStart,
|
|
32
31
|
constrainValue: () => constrainValue,
|
|
33
32
|
formatRange: () => formatRange,
|
|
34
33
|
formatSelectedDate: () => formatSelectedDate,
|
|
34
|
+
formatVisibleRange: () => formatVisibleRange,
|
|
35
35
|
getDatesInWeek: () => getDatesInWeek,
|
|
36
36
|
getEndDate: () => getEndDate,
|
|
37
37
|
getMonthDates: () => getMonthDates,
|
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
getNextPage: () => getNextPage,
|
|
40
40
|
getNextRow: () => getNextRow,
|
|
41
41
|
getNextSection: () => getNextSection,
|
|
42
|
+
getPreviousAvailableDate: () => getPreviousAvailableDate,
|
|
42
43
|
getPreviousDay: () => getPreviousDay,
|
|
43
44
|
getPreviousPage: () => getPreviousPage,
|
|
44
45
|
getPreviousRow: () => getPreviousRow,
|
|
@@ -69,8 +70,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
69
70
|
|
|
70
71
|
// src/constrain.ts
|
|
71
72
|
var import_date = require("@internationalized/date");
|
|
72
|
-
function alignCenter(
|
|
73
|
-
const { duration } = ctx;
|
|
73
|
+
function alignCenter(date, duration, locale, min, max) {
|
|
74
74
|
let halfDuration = {};
|
|
75
75
|
for (let key in duration) {
|
|
76
76
|
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
@@ -78,11 +78,10 @@ function alignCenter(ctx, date) {
|
|
|
78
78
|
halfDuration[key]--;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
let aligned = alignStart(
|
|
82
|
-
return constrainStart(
|
|
81
|
+
let aligned = alignStart(date, duration, locale).subtract(halfDuration);
|
|
82
|
+
return constrainStart(date, aligned, duration, locale, min, max);
|
|
83
83
|
}
|
|
84
|
-
function alignStart(
|
|
85
|
-
let { locale, duration } = ctx;
|
|
84
|
+
function alignStart(date, duration, locale, min, max) {
|
|
86
85
|
let aligned = date;
|
|
87
86
|
if (duration.years) {
|
|
88
87
|
aligned = (0, import_date.startOfYear)(date);
|
|
@@ -91,10 +90,9 @@ function alignStart(ctx, date) {
|
|
|
91
90
|
} else if (duration.weeks) {
|
|
92
91
|
aligned = (0, import_date.startOfWeek)(date, locale);
|
|
93
92
|
}
|
|
94
|
-
return constrainStart(
|
|
93
|
+
return constrainStart(date, aligned, duration, locale, min, max);
|
|
95
94
|
}
|
|
96
|
-
function alignEnd(
|
|
97
|
-
const { duration } = ctx;
|
|
95
|
+
function alignEnd(date, duration, locale, min, max) {
|
|
98
96
|
let d = { ...duration };
|
|
99
97
|
if (d.days) {
|
|
100
98
|
d.days--;
|
|
@@ -105,86 +103,83 @@ function alignEnd(ctx, date) {
|
|
|
105
103
|
} else if (d.years) {
|
|
106
104
|
d.years--;
|
|
107
105
|
}
|
|
108
|
-
let aligned = alignStart(
|
|
109
|
-
return constrainStart(
|
|
106
|
+
let aligned = alignStart(date, duration, locale).subtract(d);
|
|
107
|
+
return constrainStart(date, aligned, duration, locale, min, max);
|
|
110
108
|
}
|
|
111
|
-
function
|
|
112
|
-
let { min, max } = ctx;
|
|
113
|
-
if (min) {
|
|
114
|
-
date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(min));
|
|
115
|
-
}
|
|
116
|
-
if (max) {
|
|
117
|
-
date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(max));
|
|
118
|
-
}
|
|
119
|
-
return date;
|
|
120
|
-
}
|
|
121
|
-
function constrainStart(ctx, date, aligned) {
|
|
122
|
-
let { min, max } = ctx;
|
|
109
|
+
function constrainStart(date, aligned, duration, locale, min, max) {
|
|
123
110
|
if (min && date.compare(min) >= 0) {
|
|
124
|
-
aligned = (0, import_date.maxDate)(aligned, alignStart(
|
|
111
|
+
aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
|
|
125
112
|
}
|
|
126
113
|
if (max && date.compare(max) <= 0) {
|
|
127
|
-
aligned = (0, import_date.minDate)(aligned, alignEnd(
|
|
114
|
+
aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
|
|
128
115
|
}
|
|
129
116
|
return aligned;
|
|
130
117
|
}
|
|
118
|
+
function constrainValue(date, minValue, maxValue) {
|
|
119
|
+
if (minValue) {
|
|
120
|
+
date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(minValue));
|
|
121
|
+
}
|
|
122
|
+
if (maxValue) {
|
|
123
|
+
date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(maxValue));
|
|
124
|
+
}
|
|
125
|
+
return date;
|
|
126
|
+
}
|
|
131
127
|
|
|
132
128
|
// src/align.ts
|
|
133
|
-
function alignDate(
|
|
129
|
+
function alignDate(date, alignment, duration, locale, min, max) {
|
|
134
130
|
switch (alignment) {
|
|
135
131
|
case "start":
|
|
136
|
-
return alignStart(
|
|
132
|
+
return alignStart(date, duration, locale, min, max);
|
|
137
133
|
case "end":
|
|
138
|
-
return alignEnd(
|
|
134
|
+
return alignEnd(date, duration, locale, min, max);
|
|
139
135
|
case "center":
|
|
140
136
|
default:
|
|
141
|
-
return alignCenter(
|
|
137
|
+
return alignCenter(date, duration, locale, min, max);
|
|
142
138
|
}
|
|
143
139
|
}
|
|
144
|
-
function alignStartDate(
|
|
145
|
-
if (
|
|
146
|
-
return alignEnd(
|
|
140
|
+
function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
|
|
141
|
+
if (date.compare(startDate) < 0) {
|
|
142
|
+
return alignEnd(date, duration, locale, min, max);
|
|
147
143
|
}
|
|
148
|
-
if (
|
|
149
|
-
return alignStart(
|
|
144
|
+
if (date.compare(endDate) > 0) {
|
|
145
|
+
return alignStart(date, duration, locale, min, max);
|
|
150
146
|
}
|
|
151
147
|
return startDate;
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
// src/assertion.ts
|
|
155
151
|
var import_date2 = require("@internationalized/date");
|
|
156
|
-
function isTodayDate(date,
|
|
157
|
-
return (0, import_date2.isToday)(date,
|
|
152
|
+
function isTodayDate(date, timeZone) {
|
|
153
|
+
return (0, import_date2.isToday)(date, timeZone);
|
|
158
154
|
}
|
|
159
155
|
function isDateEqual(dateA, dateB) {
|
|
160
156
|
return dateB != null && (0, import_date2.isSameDay)(dateA, dateB);
|
|
161
157
|
}
|
|
162
|
-
function isDateInvalid(
|
|
163
|
-
return
|
|
158
|
+
function isDateInvalid(date, minValue, maxValue) {
|
|
159
|
+
return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
|
|
164
160
|
}
|
|
165
|
-
function isDateDisabled(
|
|
166
|
-
return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(
|
|
161
|
+
function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
|
|
162
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(date, minValue, maxValue);
|
|
167
163
|
}
|
|
168
|
-
function isDateUnavailable(
|
|
169
|
-
var _a;
|
|
164
|
+
function isDateUnavailable(date, isUnavailable, minValue, maxValue) {
|
|
170
165
|
if (!date) {
|
|
171
166
|
return false;
|
|
172
167
|
}
|
|
173
|
-
if (
|
|
168
|
+
if (isUnavailable == null ? void 0 : isUnavailable(date)) {
|
|
174
169
|
return true;
|
|
175
170
|
}
|
|
176
|
-
return isDateInvalid(
|
|
171
|
+
return isDateInvalid(date, minValue, maxValue);
|
|
177
172
|
}
|
|
178
173
|
function isDateOutsideVisibleRange(date, startDate, endDate) {
|
|
179
174
|
return date.compare(startDate) < 0 || date.compare(endDate) > 0;
|
|
180
175
|
}
|
|
181
|
-
function isPreviousVisibleRangeInvalid(
|
|
182
|
-
|
|
183
|
-
return (0, import_date2.isSameDay)(
|
|
176
|
+
function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
|
|
177
|
+
const prevDate = startDate.subtract({ days: 1 });
|
|
178
|
+
return (0, import_date2.isSameDay)(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
|
|
184
179
|
}
|
|
185
|
-
function isNextVisibleRangeInvalid(
|
|
186
|
-
|
|
187
|
-
return (0, import_date2.isSameDay)(
|
|
180
|
+
function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
|
|
181
|
+
const nextDate = endDate.add({ days: 1 });
|
|
182
|
+
return (0, import_date2.isSameDay)(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
|
|
188
183
|
}
|
|
189
184
|
|
|
190
185
|
// src/duration.ts
|
|
@@ -206,8 +201,8 @@ function getEndDate(startDate, duration) {
|
|
|
206
201
|
}
|
|
207
202
|
|
|
208
203
|
// src/format-range.ts
|
|
209
|
-
function formatRange(
|
|
210
|
-
let parts = formatter.formatRangeToParts(
|
|
204
|
+
function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
205
|
+
let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
211
206
|
let separatorIndex = -1;
|
|
212
207
|
for (let i = 0; i < parts.length; i++) {
|
|
213
208
|
let part = parts[i];
|
|
@@ -226,20 +221,19 @@ function formatRange(ctx, formatter) {
|
|
|
226
221
|
end += parts[i].value;
|
|
227
222
|
}
|
|
228
223
|
}
|
|
229
|
-
return
|
|
224
|
+
return toString(start, end);
|
|
230
225
|
}
|
|
231
226
|
|
|
232
227
|
// src/format-selected-date.ts
|
|
233
228
|
var import_date3 = require("@internationalized/date");
|
|
234
229
|
|
|
235
|
-
// src/get-
|
|
230
|
+
// src/get-formatter.ts
|
|
236
231
|
function getEraFormat(date) {
|
|
237
232
|
return (date == null ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
238
233
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const { start, end = start, getDateFormatter: getDateFormatter2, timeZone } = ctx;
|
|
234
|
+
function getDateFormatter(startDate, endDate, getDateFormatter2, timeZone) {
|
|
235
|
+
let start = startDate;
|
|
236
|
+
let end = endDate != null ? endDate : startDate;
|
|
243
237
|
let era = getEraFormat(start) || getEraFormat(end);
|
|
244
238
|
return getDateFormatter2({
|
|
245
239
|
weekday: "long",
|
|
@@ -250,34 +244,67 @@ function getDateFormatter(ctx) {
|
|
|
250
244
|
timeZone
|
|
251
245
|
});
|
|
252
246
|
}
|
|
247
|
+
function getMonthFormatter(startDate, endDate, getDateFormatter2, timeZone) {
|
|
248
|
+
let start = startDate;
|
|
249
|
+
let end = endDate != null ? endDate : startDate;
|
|
250
|
+
let era = getEraFormat(start) || getEraFormat(end);
|
|
251
|
+
return getDateFormatter2({
|
|
252
|
+
month: "long",
|
|
253
|
+
year: "numeric",
|
|
254
|
+
era,
|
|
255
|
+
calendar: start == null ? void 0 : start.calendar.identifier,
|
|
256
|
+
timeZone
|
|
257
|
+
});
|
|
258
|
+
}
|
|
253
259
|
|
|
254
260
|
// src/format-selected-date.ts
|
|
255
|
-
function formatSelectedDate(
|
|
256
|
-
|
|
257
|
-
let
|
|
258
|
-
|
|
261
|
+
function formatSelectedDate(startDate, endDate, getFormatter, isSelectingRange, timeZone) {
|
|
262
|
+
let start = startDate;
|
|
263
|
+
let end = endDate != null ? endDate : startDate;
|
|
264
|
+
let formatter = getDateFormatter(start, end, getFormatter, timeZone);
|
|
265
|
+
if (isSelectingRange || start == null || end == null) {
|
|
259
266
|
return "";
|
|
260
267
|
}
|
|
261
268
|
if ((0, import_date3.isSameDay)(start, end)) {
|
|
262
269
|
return formatter.format(start.toDate(timeZone));
|
|
263
270
|
}
|
|
264
|
-
return formatRange(
|
|
271
|
+
return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
|
|
265
272
|
}
|
|
266
273
|
|
|
267
|
-
// src/
|
|
274
|
+
// src/format-visible-range.ts
|
|
268
275
|
var import_date4 = require("@internationalized/date");
|
|
276
|
+
function formatVisibleRange(startDate, endDate, getFormatter, isAria, timeZone) {
|
|
277
|
+
if (!startDate)
|
|
278
|
+
return "";
|
|
279
|
+
let start = startDate;
|
|
280
|
+
let end = endDate != null ? endDate : startDate;
|
|
281
|
+
let monthFormatter = getMonthFormatter(start, end, getFormatter, timeZone);
|
|
282
|
+
let dateFormatter = getDateFormatter(start, end, getFormatter, timeZone);
|
|
283
|
+
if (!(0, import_date4.isSameDay)(start, (0, import_date4.startOfMonth)(start))) {
|
|
284
|
+
return isAria ? formatRange(start, end, dateFormatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone) : dateFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
285
|
+
}
|
|
286
|
+
if ((0, import_date4.isSameDay)(end, (0, import_date4.endOfMonth)(start))) {
|
|
287
|
+
return monthFormatter.format(start.toDate(timeZone));
|
|
288
|
+
}
|
|
289
|
+
if ((0, import_date4.isSameDay)(end, (0, import_date4.endOfMonth)(end))) {
|
|
290
|
+
return isAria ? formatRange(start, end, monthFormatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone) : monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/get-week-dates.ts
|
|
295
|
+
var import_date5 = require("@internationalized/date");
|
|
269
296
|
function getDatesInWeek(weekIndex, fromDate, locale) {
|
|
270
297
|
let date = fromDate.add({ weeks: weekIndex });
|
|
271
298
|
let dates = [];
|
|
272
|
-
date = (0,
|
|
273
|
-
let dayOfWeek = (0,
|
|
299
|
+
date = (0, import_date5.startOfWeek)(date, locale);
|
|
300
|
+
let dayOfWeek = (0, import_date5.getDayOfWeek)(date, locale);
|
|
274
301
|
for (let i = 0; i < dayOfWeek; i++) {
|
|
275
302
|
dates.push(null);
|
|
276
303
|
}
|
|
277
304
|
while (dates.length < 7) {
|
|
278
305
|
dates.push(date);
|
|
279
306
|
let nextDate = date.add({ days: 1 });
|
|
280
|
-
if ((0,
|
|
307
|
+
if ((0, import_date5.isSameDay)(date, nextDate)) {
|
|
281
308
|
break;
|
|
282
309
|
}
|
|
283
310
|
date = nextDate;
|
|
@@ -287,8 +314,8 @@ function getDatesInWeek(weekIndex, fromDate, locale) {
|
|
|
287
314
|
}
|
|
288
315
|
return dates;
|
|
289
316
|
}
|
|
290
|
-
function getWeekDates(timeZone, locale) {
|
|
291
|
-
let weekStart = (0,
|
|
317
|
+
function getWeekDates(fromDate, timeZone, locale) {
|
|
318
|
+
let weekStart = (0, import_date5.startOfWeek)(fromDate, locale);
|
|
292
319
|
let weekArr = [...new Array(7).keys()];
|
|
293
320
|
return weekArr.map((index) => {
|
|
294
321
|
return weekStart.add({ days: index }).toDate(timeZone);
|
|
@@ -296,10 +323,10 @@ function getWeekDates(timeZone, locale) {
|
|
|
296
323
|
}
|
|
297
324
|
|
|
298
325
|
// src/get-month-dates.ts
|
|
299
|
-
var
|
|
326
|
+
var import_date6 = require("@internationalized/date");
|
|
300
327
|
function getMonthDates(startDate, duration, locale) {
|
|
301
328
|
var _a;
|
|
302
|
-
let weeksInMonth = (0,
|
|
329
|
+
let weeksInMonth = (0, import_date6.getWeeksInMonth)(startDate, locale);
|
|
303
330
|
let numOfWeeks = (_a = duration.weeks) != null ? _a : weeksInMonth;
|
|
304
331
|
let weekArr = [...new Array(numOfWeeks).keys()];
|
|
305
332
|
return weekArr.map((index) => {
|
|
@@ -317,12 +344,9 @@ function getYearsRange(range) {
|
|
|
317
344
|
}
|
|
318
345
|
|
|
319
346
|
// src/mutation.ts
|
|
320
|
-
var
|
|
321
|
-
function clampDate(ctx, date) {
|
|
322
|
-
return constrainValue(ctx, date);
|
|
323
|
-
}
|
|
347
|
+
var import_date7 = require("@internationalized/date");
|
|
324
348
|
function getTodayDate(timezone) {
|
|
325
|
-
return (0,
|
|
349
|
+
return (0, import_date7.today)(timezone);
|
|
326
350
|
}
|
|
327
351
|
function getNextDay(date) {
|
|
328
352
|
return date.add({ days: 1 });
|
|
@@ -337,26 +361,19 @@ function setYear(date, year) {
|
|
|
337
361
|
return date.set({ year });
|
|
338
362
|
}
|
|
339
363
|
function setCalendar(date, calendar) {
|
|
340
|
-
return (0,
|
|
364
|
+
return (0, import_date7.toCalendar)((0, import_date7.toCalendarDate)(date), calendar);
|
|
341
365
|
}
|
|
342
|
-
function setDate(
|
|
366
|
+
function setDate(date, startDate, isDateUnavailable2, minValue, maxValue) {
|
|
343
367
|
let result;
|
|
344
|
-
result =
|
|
345
|
-
result = getPreviousAvailableDate(
|
|
346
|
-
if (!result)
|
|
347
|
-
return;
|
|
348
|
-
result = (0, import_date6.toCalendar)(result, (date == null ? void 0 : date.calendar) || new import_date6.GregorianCalendar());
|
|
349
|
-
if (date && "hour" in date) {
|
|
350
|
-
return date.set(result);
|
|
351
|
-
}
|
|
368
|
+
result = constrainValue(date, minValue, maxValue);
|
|
369
|
+
result = getPreviousAvailableDate(date, startDate, isDateUnavailable2);
|
|
352
370
|
return result;
|
|
353
371
|
}
|
|
354
|
-
function getPreviousAvailableDate(
|
|
355
|
-
|
|
356
|
-
if (!isDateUnavailable(ctx, date) || !minValue) {
|
|
372
|
+
function getPreviousAvailableDate(date, minValue, isDateUnavailable2) {
|
|
373
|
+
if (!isDateUnavailable2) {
|
|
357
374
|
return date;
|
|
358
375
|
}
|
|
359
|
-
while (date.compare(minValue) >= 0 &&
|
|
376
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable2(date)) {
|
|
360
377
|
date = date.subtract({ days: 1 });
|
|
361
378
|
}
|
|
362
379
|
if (date.compare(minValue) >= 0) {
|
|
@@ -365,93 +382,176 @@ function getPreviousAvailableDate(ctx, date, min) {
|
|
|
365
382
|
}
|
|
366
383
|
|
|
367
384
|
// src/pagination.ts
|
|
368
|
-
var
|
|
369
|
-
function
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
385
|
+
var import_date8 = require("@internationalized/date");
|
|
386
|
+
function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
|
|
387
|
+
return function getDate(options) {
|
|
388
|
+
const { startDate, focusedDate } = options;
|
|
389
|
+
const endDate = getEndDate(startDate, visibleDuration);
|
|
390
|
+
if (isDateInvalid(focusedDate, minValue, maxValue)) {
|
|
391
|
+
return {
|
|
392
|
+
startDate,
|
|
393
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue),
|
|
394
|
+
endDate
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
398
|
+
return {
|
|
399
|
+
startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
400
|
+
endDate,
|
|
401
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
405
|
+
return {
|
|
406
|
+
startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
407
|
+
endDate,
|
|
408
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
startDate,
|
|
413
|
+
endDate,
|
|
414
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
415
|
+
};
|
|
381
416
|
};
|
|
382
417
|
}
|
|
383
|
-
function
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function getSectionEnd(ctx, date, endDate) {
|
|
396
|
-
const d = ctx.duration;
|
|
397
|
-
if (d.days) {
|
|
398
|
-
return endDate;
|
|
399
|
-
}
|
|
400
|
-
if (d.weeks) {
|
|
401
|
-
return (0, import_date7.endOfWeek)(date, ctx.locale);
|
|
402
|
-
}
|
|
403
|
-
if (d.months || d.years) {
|
|
404
|
-
return (0, import_date7.endOfMonth)(date);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
function getNextSection(ctx, date, larger) {
|
|
408
|
-
const d = ctx.duration;
|
|
409
|
-
const unitDuration = getUnitDuration(ctx.duration);
|
|
410
|
-
if (!larger && !d.days) {
|
|
411
|
-
return date.add(unitDuration);
|
|
412
|
-
}
|
|
413
|
-
if (d.days) {
|
|
414
|
-
return date.add(d);
|
|
415
|
-
}
|
|
416
|
-
if (d.weeks) {
|
|
417
|
-
return date.add({ months: 1 });
|
|
418
|
-
}
|
|
419
|
-
if (d.months || d.years) {
|
|
420
|
-
return date.add({ years: 1 });
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function getPreviousSection(ctx, date, larger) {
|
|
424
|
-
const d = ctx.duration;
|
|
425
|
-
const unitDuration = getUnitDuration(ctx.duration);
|
|
426
|
-
if (!larger && !d.days) {
|
|
427
|
-
return date.subtract(unitDuration);
|
|
428
|
-
}
|
|
429
|
-
if (d.days) {
|
|
430
|
-
return date.subtract(ctx.duration);
|
|
431
|
-
}
|
|
432
|
-
if (d.weeks) {
|
|
433
|
-
return date.subtract({ months: 1 });
|
|
434
|
-
}
|
|
435
|
-
if (d.months || d.years) {
|
|
436
|
-
return date.subtract({ years: 1 });
|
|
437
|
-
}
|
|
418
|
+
function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
419
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
420
|
+
const start = startDate.add(visibleDuration);
|
|
421
|
+
return adjust({
|
|
422
|
+
focusedDate: focusedDate.add(visibleDuration),
|
|
423
|
+
startDate: alignStart(
|
|
424
|
+
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
425
|
+
visibleDuration,
|
|
426
|
+
locale
|
|
427
|
+
)
|
|
428
|
+
});
|
|
438
429
|
}
|
|
439
|
-
function
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
430
|
+
function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
431
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
432
|
+
let start = startDate.subtract(visibleDuration);
|
|
433
|
+
return adjust({
|
|
434
|
+
focusedDate: focusedDate.subtract(visibleDuration),
|
|
435
|
+
startDate: alignStart(
|
|
436
|
+
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
437
|
+
visibleDuration,
|
|
438
|
+
locale
|
|
439
|
+
)
|
|
440
|
+
});
|
|
447
441
|
}
|
|
448
|
-
function
|
|
449
|
-
const
|
|
450
|
-
if (
|
|
451
|
-
return
|
|
452
|
-
}
|
|
453
|
-
if (
|
|
454
|
-
return
|
|
442
|
+
function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
443
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
444
|
+
if (visibleDuration.days) {
|
|
445
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
446
|
+
}
|
|
447
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
448
|
+
return adjust({
|
|
449
|
+
focusedDate: focusedDate.add({ weeks: 1 }),
|
|
450
|
+
startDate
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
455
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
456
|
+
if (visibleDuration.days) {
|
|
457
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
458
|
+
}
|
|
459
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
460
|
+
return adjust({
|
|
461
|
+
focusedDate: focusedDate.subtract({ weeks: 1 }),
|
|
462
|
+
startDate
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
467
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
468
|
+
if (visibleDuration.days) {
|
|
469
|
+
return adjust({
|
|
470
|
+
focusedDate: startDate,
|
|
471
|
+
startDate
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (visibleDuration.weeks) {
|
|
475
|
+
return adjust({
|
|
476
|
+
focusedDate: (0, import_date8.startOfWeek)(focusedDate, locale),
|
|
477
|
+
startDate
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
481
|
+
return adjust({
|
|
482
|
+
focusedDate: (0, import_date8.startOfMonth)(focusedDate),
|
|
483
|
+
startDate
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
488
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
489
|
+
const endDate = getEndDate(startDate, visibleDuration);
|
|
490
|
+
if (visibleDuration.days) {
|
|
491
|
+
return adjust({
|
|
492
|
+
focusedDate: endDate,
|
|
493
|
+
startDate
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
if (visibleDuration.weeks) {
|
|
497
|
+
return adjust({
|
|
498
|
+
focusedDate: (0, import_date8.endOfWeek)(focusedDate, locale),
|
|
499
|
+
startDate
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
503
|
+
return adjust({
|
|
504
|
+
focusedDate: (0, import_date8.endOfMonth)(focusedDate),
|
|
505
|
+
startDate
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
510
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
511
|
+
if (!larger && !visibleDuration.days) {
|
|
512
|
+
return adjust({
|
|
513
|
+
focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
|
|
514
|
+
startDate
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
if (visibleDuration.days) {
|
|
518
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
519
|
+
}
|
|
520
|
+
if (visibleDuration.weeks) {
|
|
521
|
+
return adjust({
|
|
522
|
+
focusedDate: focusedDate.add({ months: 1 }),
|
|
523
|
+
startDate
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
527
|
+
return adjust({
|
|
528
|
+
focusedDate: focusedDate.add({ years: 1 }),
|
|
529
|
+
startDate
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
534
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
535
|
+
if (!larger && !visibleDuration.days) {
|
|
536
|
+
return adjust({
|
|
537
|
+
focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
|
|
538
|
+
startDate
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
if (visibleDuration.days) {
|
|
542
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
543
|
+
}
|
|
544
|
+
if (visibleDuration.weeks) {
|
|
545
|
+
return adjust({
|
|
546
|
+
focusedDate: focusedDate.subtract({ months: 1 }),
|
|
547
|
+
startDate
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
551
|
+
return adjust({
|
|
552
|
+
focusedDate: focusedDate.subtract({ years: 1 }),
|
|
553
|
+
startDate
|
|
554
|
+
});
|
|
455
555
|
}
|
|
456
556
|
}
|
|
457
557
|
|
|
@@ -479,7 +579,7 @@ function isSegmentEditable(segment) {
|
|
|
479
579
|
}
|
|
480
580
|
|
|
481
581
|
// src/segment-limit.ts
|
|
482
|
-
var
|
|
582
|
+
var import_date9 = require("@internationalized/date");
|
|
483
583
|
function getSegmentLimits(date, type, options) {
|
|
484
584
|
switch (type) {
|
|
485
585
|
case "era": {
|
|
@@ -499,13 +599,13 @@ function getSegmentLimits(date, type, options) {
|
|
|
499
599
|
case "month":
|
|
500
600
|
return {
|
|
501
601
|
value: date.month,
|
|
502
|
-
min: (0,
|
|
602
|
+
min: (0, import_date9.getMinimumMonthInYear)(date),
|
|
503
603
|
max: date.calendar.getMonthsInYear(date)
|
|
504
604
|
};
|
|
505
605
|
case "day":
|
|
506
606
|
return {
|
|
507
607
|
value: date.day,
|
|
508
|
-
min: (0,
|
|
608
|
+
min: (0, import_date9.getMinimumDayInMonth)(date),
|
|
509
609
|
max: date.calendar.getDaysInMonth(date)
|
|
510
610
|
};
|
|
511
611
|
}
|
|
@@ -518,7 +618,7 @@ function getSegmentLimits(date, type, options) {
|
|
|
518
618
|
max: 12
|
|
519
619
|
};
|
|
520
620
|
case "hour":
|
|
521
|
-
if (options.hour12) {
|
|
621
|
+
if (options == null ? void 0 : options.hour12) {
|
|
522
622
|
let isPM = date.hour >= 12;
|
|
523
623
|
return {
|
|
524
624
|
value: date.hour,
|
|
@@ -569,10 +669,11 @@ function addSegment(date, part, amount, options) {
|
|
|
569
669
|
case "second":
|
|
570
670
|
return date.cycle(part, amount, {
|
|
571
671
|
round: part !== "hour",
|
|
572
|
-
hourCycle: options.hour12 ? 12 : 24
|
|
672
|
+
hourCycle: (options == null ? void 0 : options.hour12) ? 12 : 24
|
|
573
673
|
});
|
|
574
674
|
}
|
|
575
675
|
}
|
|
676
|
+
return date;
|
|
576
677
|
}
|
|
577
678
|
function setSegment(date, part, value, options) {
|
|
578
679
|
switch (part) {
|
|
@@ -591,7 +692,7 @@ function setSegment(date, part, value, options) {
|
|
|
591
692
|
return isPM === wasPM ? date : date.set({ hour: wasPM ? hours - 12 : hours + 12 });
|
|
592
693
|
}
|
|
593
694
|
case "hour":
|
|
594
|
-
if (options.hour12) {
|
|
695
|
+
if (options == null ? void 0 : options.hour12) {
|
|
595
696
|
let hours = date.hour;
|
|
596
697
|
let wasPM = hours >= 12;
|
|
597
698
|
if (!wasPM && value === 12) {
|
|
@@ -606,6 +707,7 @@ function setSegment(date, part, value, options) {
|
|
|
606
707
|
return date.set({ [part]: value });
|
|
607
708
|
}
|
|
608
709
|
}
|
|
710
|
+
return date;
|
|
609
711
|
}
|
|
610
712
|
// Annotate the CommonJS export names for ESM import in node:
|
|
611
713
|
0 && (module.exports = {
|
|
@@ -616,11 +718,11 @@ function setSegment(date, part, value, options) {
|
|
|
616
718
|
alignEnd,
|
|
617
719
|
alignStart,
|
|
618
720
|
alignStartDate,
|
|
619
|
-
clampDate,
|
|
620
721
|
constrainStart,
|
|
621
722
|
constrainValue,
|
|
622
723
|
formatRange,
|
|
623
724
|
formatSelectedDate,
|
|
725
|
+
formatVisibleRange,
|
|
624
726
|
getDatesInWeek,
|
|
625
727
|
getEndDate,
|
|
626
728
|
getMonthDates,
|
|
@@ -628,6 +730,7 @@ function setSegment(date, part, value, options) {
|
|
|
628
730
|
getNextPage,
|
|
629
731
|
getNextRow,
|
|
630
732
|
getNextSection,
|
|
733
|
+
getPreviousAvailableDate,
|
|
631
734
|
getPreviousDay,
|
|
632
735
|
getPreviousPage,
|
|
633
736
|
getPreviousRow,
|