@zag-js/date-utils 0.69.0 → 0.71.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/index.js +120 -230
- package/dist/index.mjs +31 -141
- package/package.json +2 -3
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/align.ts +0 -40
- package/src/assertion.ts +0 -62
- package/src/constrain.ts +0 -117
- package/src/duration.ts +0 -23
- package/src/format-range.ts +0 -35
- package/src/format-selected-date.ts +0 -16
- package/src/format-visible-range.ts +0 -26
- package/src/get-day-formatter.ts +0 -14
- package/src/get-decade-range.ts +0 -12
- package/src/get-end-of-week.ts +0 -6
- package/src/get-era-format.ts +0 -5
- package/src/get-month-days.ts +0 -33
- package/src/get-month-formatter.ts +0 -13
- package/src/get-month-names.ts +0 -9
- package/src/get-start-of-week.ts +0 -14
- package/src/get-week-days.ts +0 -10
- package/src/get-weekday-formats.ts +0 -16
- package/src/get-year-range.ts +0 -14
- package/src/index.ts +0 -20
- package/src/mutation.ts +0 -67
- package/src/normalize-year.ts +0 -20
- package/src/pagination.ts +0 -301
- package/src/parse-date.ts +0 -73
- package/src/preset.ts +0 -63
- package/src/types.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -1,79 +1,8 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
alignCenter: () => alignCenter,
|
|
24
|
-
alignDate: () => alignDate,
|
|
25
|
-
alignEnd: () => alignEnd,
|
|
26
|
-
alignStart: () => alignStart,
|
|
27
|
-
alignStartDate: () => alignStartDate,
|
|
28
|
-
constrainStart: () => constrainStart,
|
|
29
|
-
constrainValue: () => constrainValue,
|
|
30
|
-
formatRange: () => formatRange,
|
|
31
|
-
formatSelectedDate: () => formatSelectedDate,
|
|
32
|
-
formatVisibleRange: () => formatVisibleRange,
|
|
33
|
-
getAdjustedDateFn: () => getAdjustedDateFn,
|
|
34
|
-
getCustomWeeksInMonth: () => getCustomWeeksInMonth,
|
|
35
|
-
getDateRangePreset: () => getDateRangePreset,
|
|
36
|
-
getDayFormatter: () => getDayFormatter,
|
|
37
|
-
getDaysInWeek: () => getDaysInWeek,
|
|
38
|
-
getDecadeRange: () => getDecadeRange,
|
|
39
|
-
getEndDate: () => getEndDate,
|
|
40
|
-
getMonthDays: () => getMonthDays,
|
|
41
|
-
getMonthFormatter: () => getMonthFormatter,
|
|
42
|
-
getMonthNames: () => getMonthNames,
|
|
43
|
-
getNextDay: () => getNextDay,
|
|
44
|
-
getNextPage: () => getNextPage,
|
|
45
|
-
getNextRow: () => getNextRow,
|
|
46
|
-
getNextSection: () => getNextSection,
|
|
47
|
-
getPreviousAvailableDate: () => getPreviousAvailableDate,
|
|
48
|
-
getPreviousDay: () => getPreviousDay,
|
|
49
|
-
getPreviousPage: () => getPreviousPage,
|
|
50
|
-
getPreviousRow: () => getPreviousRow,
|
|
51
|
-
getPreviousSection: () => getPreviousSection,
|
|
52
|
-
getSectionEnd: () => getSectionEnd,
|
|
53
|
-
getSectionStart: () => getSectionStart,
|
|
54
|
-
getTodayDate: () => getTodayDate,
|
|
55
|
-
getUnitDuration: () => getUnitDuration,
|
|
56
|
-
getWeekDays: () => getWeekDays,
|
|
57
|
-
getWeekdayFormats: () => getWeekdayFormats,
|
|
58
|
-
getYearsRange: () => getYearsRange,
|
|
59
|
-
isDateDisabled: () => isDateDisabled,
|
|
60
|
-
isDateEqual: () => isDateEqual,
|
|
61
|
-
isDateInvalid: () => isDateInvalid,
|
|
62
|
-
isDateOutsideVisibleRange: () => isDateOutsideVisibleRange,
|
|
63
|
-
isDateUnavailable: () => isDateUnavailable,
|
|
64
|
-
isNextVisibleRangeInvalid: () => isNextVisibleRangeInvalid,
|
|
65
|
-
isPreviousVisibleRangeInvalid: () => isPreviousVisibleRangeInvalid,
|
|
66
|
-
isTodayDate: () => isTodayDate,
|
|
67
|
-
parseDateString: () => parseDateString,
|
|
68
|
-
setCalendar: () => setCalendar,
|
|
69
|
-
setDate: () => setDate,
|
|
70
|
-
setMonth: () => setMonth,
|
|
71
|
-
setYear: () => setYear
|
|
72
|
-
});
|
|
73
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var date = require('@internationalized/date');
|
|
74
4
|
|
|
75
5
|
// src/constrain.ts
|
|
76
|
-
var import_date = require("@internationalized/date");
|
|
77
6
|
function alignCenter(date, duration, locale, min, max) {
|
|
78
7
|
const halfDuration = {};
|
|
79
8
|
for (let prop in duration) {
|
|
@@ -88,16 +17,16 @@ function alignCenter(date, duration, locale, min, max) {
|
|
|
88
17
|
const aligned = alignStart(date, duration, locale).subtract(halfDuration);
|
|
89
18
|
return constrainStart(date, aligned, duration, locale, min, max);
|
|
90
19
|
}
|
|
91
|
-
function alignStart(date, duration, locale, min, max) {
|
|
92
|
-
let aligned = date;
|
|
20
|
+
function alignStart(date$1, duration, locale, min, max) {
|
|
21
|
+
let aligned = date$1;
|
|
93
22
|
if (duration.years) {
|
|
94
|
-
aligned =
|
|
23
|
+
aligned = date.startOfYear(date$1);
|
|
95
24
|
} else if (duration.months) {
|
|
96
|
-
aligned =
|
|
25
|
+
aligned = date.startOfMonth(date$1);
|
|
97
26
|
} else if (duration.weeks) {
|
|
98
|
-
aligned =
|
|
27
|
+
aligned = date.startOfWeek(date$1, locale);
|
|
99
28
|
}
|
|
100
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
29
|
+
return constrainStart(date$1, aligned, duration, locale, min, max);
|
|
101
30
|
}
|
|
102
31
|
function alignEnd(date, duration, locale, min, max) {
|
|
103
32
|
let d = { ...duration };
|
|
@@ -113,23 +42,23 @@ function alignEnd(date, duration, locale, min, max) {
|
|
|
113
42
|
let aligned = alignStart(date, duration, locale).subtract(d);
|
|
114
43
|
return constrainStart(date, aligned, duration, locale, min, max);
|
|
115
44
|
}
|
|
116
|
-
function constrainStart(date, aligned, duration, locale, min, max) {
|
|
117
|
-
if (min && date.compare(min) >= 0) {
|
|
118
|
-
aligned =
|
|
45
|
+
function constrainStart(date$1, aligned, duration, locale, min, max) {
|
|
46
|
+
if (min && date$1.compare(min) >= 0) {
|
|
47
|
+
aligned = date.maxDate(aligned, alignStart(date.toCalendarDate(min), duration, locale));
|
|
119
48
|
}
|
|
120
|
-
if (max && date.compare(max) <= 0) {
|
|
121
|
-
aligned =
|
|
49
|
+
if (max && date$1.compare(max) <= 0) {
|
|
50
|
+
aligned = date.minDate(aligned, alignEnd(date.toCalendarDate(max), duration, locale));
|
|
122
51
|
}
|
|
123
52
|
return aligned;
|
|
124
53
|
}
|
|
125
|
-
function constrainValue(date, minValue, maxValue) {
|
|
54
|
+
function constrainValue(date$1, minValue, maxValue) {
|
|
126
55
|
if (minValue) {
|
|
127
|
-
date =
|
|
56
|
+
date$1 = date.maxDate(date$1, date.toCalendarDate(minValue));
|
|
128
57
|
}
|
|
129
58
|
if (maxValue) {
|
|
130
|
-
date =
|
|
59
|
+
date$1 = date.minDate(date$1, date.toCalendarDate(maxValue));
|
|
131
60
|
}
|
|
132
|
-
return date;
|
|
61
|
+
return date$1;
|
|
133
62
|
}
|
|
134
63
|
|
|
135
64
|
// src/align.ts
|
|
@@ -153,14 +82,11 @@ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
|
|
|
153
82
|
}
|
|
154
83
|
return startDate;
|
|
155
84
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var import_date2 = require("@internationalized/date");
|
|
159
|
-
function isTodayDate(date, timeZone) {
|
|
160
|
-
return (0, import_date2.isToday)(date, timeZone);
|
|
85
|
+
function isTodayDate(date$1, timeZone) {
|
|
86
|
+
return date.isToday(date$1, timeZone);
|
|
161
87
|
}
|
|
162
88
|
function isDateEqual(dateA, dateB) {
|
|
163
|
-
return dateB != null &&
|
|
89
|
+
return dateB != null && date.isSameDay(dateA, dateB);
|
|
164
90
|
}
|
|
165
91
|
function isDateInvalid(date, minValue, maxValue) {
|
|
166
92
|
return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
|
|
@@ -182,11 +108,11 @@ function isDateOutsideVisibleRange(date, startDate, endDate) {
|
|
|
182
108
|
}
|
|
183
109
|
function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
|
|
184
110
|
const prevDate = startDate.subtract({ days: 1 });
|
|
185
|
-
return
|
|
111
|
+
return date.isSameDay(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
|
|
186
112
|
}
|
|
187
113
|
function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
|
|
188
114
|
const nextDate = endDate.add({ days: 1 });
|
|
189
|
-
return
|
|
115
|
+
return date.isSameDay(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
|
|
190
116
|
}
|
|
191
117
|
|
|
192
118
|
// src/duration.ts
|
|
@@ -231,12 +157,6 @@ function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
|
231
157
|
return toString(start, end);
|
|
232
158
|
}
|
|
233
159
|
|
|
234
|
-
// src/format-selected-date.ts
|
|
235
|
-
var import_date4 = require("@internationalized/date");
|
|
236
|
-
|
|
237
|
-
// src/get-day-formatter.ts
|
|
238
|
-
var import_date3 = require("@internationalized/date");
|
|
239
|
-
|
|
240
160
|
// src/get-era-format.ts
|
|
241
161
|
function getEraFormat(date) {
|
|
242
162
|
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
@@ -244,13 +164,13 @@ function getEraFormat(date) {
|
|
|
244
164
|
|
|
245
165
|
// src/get-day-formatter.ts
|
|
246
166
|
function getDayFormatter(locale, timeZone) {
|
|
247
|
-
const date =
|
|
248
|
-
return new
|
|
167
|
+
const date$1 = date.toCalendarDateTime(date.today(timeZone));
|
|
168
|
+
return new date.DateFormatter(locale, {
|
|
249
169
|
weekday: "long",
|
|
250
170
|
month: "long",
|
|
251
171
|
year: "numeric",
|
|
252
172
|
day: "numeric",
|
|
253
|
-
era: getEraFormat(date),
|
|
173
|
+
era: getEraFormat(date$1),
|
|
254
174
|
timeZone
|
|
255
175
|
});
|
|
256
176
|
}
|
|
@@ -260,24 +180,18 @@ function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
|
260
180
|
let start = startDate;
|
|
261
181
|
let end = endDate ?? startDate;
|
|
262
182
|
let formatter = getDayFormatter(locale, timeZone);
|
|
263
|
-
if (
|
|
183
|
+
if (date.isSameDay(start, end)) {
|
|
264
184
|
return formatter.format(start.toDate(timeZone));
|
|
265
185
|
}
|
|
266
186
|
return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
|
|
267
187
|
}
|
|
268
|
-
|
|
269
|
-
// src/format-visible-range.ts
|
|
270
|
-
var import_date6 = require("@internationalized/date");
|
|
271
|
-
|
|
272
|
-
// src/get-month-formatter.ts
|
|
273
|
-
var import_date5 = require("@internationalized/date");
|
|
274
188
|
function getMonthFormatter(locale, timeZone) {
|
|
275
|
-
const date =
|
|
276
|
-
return new
|
|
189
|
+
const date$1 = date.toCalendarDate(date.today(timeZone));
|
|
190
|
+
return new date.DateFormatter(locale, {
|
|
277
191
|
month: "long",
|
|
278
192
|
year: "numeric",
|
|
279
|
-
era: getEraFormat(date),
|
|
280
|
-
calendar: date?.calendar.identifier,
|
|
193
|
+
era: getEraFormat(date$1),
|
|
194
|
+
calendar: date$1?.calendar.identifier,
|
|
281
195
|
timeZone
|
|
282
196
|
});
|
|
283
197
|
}
|
|
@@ -287,14 +201,14 @@ function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
|
287
201
|
const start = startDate;
|
|
288
202
|
const end = endDate ?? startDate;
|
|
289
203
|
const dayFormatter = getDayFormatter(locale, timeZone);
|
|
290
|
-
if (!
|
|
204
|
+
if (!date.isSameDay(start, date.startOfMonth(start))) {
|
|
291
205
|
return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
292
206
|
}
|
|
293
207
|
const monthFormatter = getMonthFormatter(locale, timeZone);
|
|
294
|
-
if (
|
|
208
|
+
if (date.isSameDay(end, date.endOfMonth(start))) {
|
|
295
209
|
return monthFormatter.format(start.toDate(timeZone));
|
|
296
210
|
}
|
|
297
|
-
if (
|
|
211
|
+
if (date.isSameDay(end, date.endOfMonth(end))) {
|
|
298
212
|
return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
299
213
|
}
|
|
300
214
|
return "";
|
|
@@ -310,41 +224,35 @@ function getDecadeRange(year) {
|
|
|
310
224
|
}
|
|
311
225
|
return years;
|
|
312
226
|
}
|
|
313
|
-
|
|
314
|
-
// src/get-month-days.ts
|
|
315
|
-
var import_date8 = require("@internationalized/date");
|
|
316
|
-
|
|
317
|
-
// src/get-start-of-week.ts
|
|
318
|
-
var import_date7 = require("@internationalized/date");
|
|
319
|
-
function getStartOfWeek(date, locale, firstDayOfWeek) {
|
|
227
|
+
function getStartOfWeek(date$1, locale, firstDayOfWeek) {
|
|
320
228
|
if (firstDayOfWeek !== void 0) {
|
|
321
|
-
const currentDayOfWeek =
|
|
229
|
+
const currentDayOfWeek = date.getDayOfWeek(date$1, locale);
|
|
322
230
|
const daysToSubtract = (currentDayOfWeek - firstDayOfWeek + 7) % 7;
|
|
323
|
-
return date.subtract({ days: daysToSubtract });
|
|
231
|
+
return date$1.subtract({ days: daysToSubtract });
|
|
324
232
|
}
|
|
325
|
-
return
|
|
233
|
+
return date.startOfWeek(date$1, locale);
|
|
326
234
|
}
|
|
327
235
|
|
|
328
236
|
// src/get-month-days.ts
|
|
329
237
|
function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
330
238
|
const weekDate = from.add({ weeks: weekIndex });
|
|
331
239
|
const dates = [];
|
|
332
|
-
let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
|
|
240
|
+
let date$1 = getStartOfWeek(weekDate, locale, firstDayOfWeek);
|
|
333
241
|
while (dates.length < 7) {
|
|
334
|
-
dates.push(date);
|
|
335
|
-
let nextDate = date.add({ days: 1 });
|
|
336
|
-
if (
|
|
242
|
+
dates.push(date$1);
|
|
243
|
+
let nextDate = date$1.add({ days: 1 });
|
|
244
|
+
if (date.isSameDay(date$1, nextDate)) {
|
|
337
245
|
break;
|
|
338
246
|
}
|
|
339
|
-
date = nextDate;
|
|
247
|
+
date$1 = nextDate;
|
|
340
248
|
}
|
|
341
249
|
return dates;
|
|
342
250
|
}
|
|
343
251
|
function getCustomWeeksInMonth(from, locale, firstDayOfWeek) {
|
|
344
252
|
if (firstDayOfWeek == null) {
|
|
345
|
-
return
|
|
253
|
+
return date.getWeeksInMonth(from, locale);
|
|
346
254
|
}
|
|
347
|
-
const paddingDays = (
|
|
255
|
+
const paddingDays = (date.getDayOfWeek(date.startOfMonth(from), locale) - firstDayOfWeek + 7) % 7;
|
|
348
256
|
return Math.ceil((paddingDays + from.calendar.getDaysInMonth(from)) / 7);
|
|
349
257
|
}
|
|
350
258
|
function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
|
|
@@ -363,13 +271,10 @@ function getMonthNames(locale, format = "long") {
|
|
|
363
271
|
}
|
|
364
272
|
return monthNames;
|
|
365
273
|
}
|
|
366
|
-
|
|
367
|
-
// src/get-weekday-formats.ts
|
|
368
|
-
var import_date9 = require("@internationalized/date");
|
|
369
274
|
function getWeekdayFormats(locale, timeZone) {
|
|
370
|
-
const longFormat = new
|
|
371
|
-
const shortFormat = new
|
|
372
|
-
const narrowFormat = new
|
|
275
|
+
const longFormat = new date.DateFormatter(locale, { weekday: "long", timeZone });
|
|
276
|
+
const shortFormat = new date.DateFormatter(locale, { weekday: "short", timeZone });
|
|
277
|
+
const narrowFormat = new date.DateFormatter(locale, { weekday: "narrow", timeZone });
|
|
373
278
|
return (value) => {
|
|
374
279
|
const date = value instanceof Date ? value : value.toDate(timeZone);
|
|
375
280
|
return {
|
|
@@ -397,11 +302,8 @@ function getYearsRange(range) {
|
|
|
397
302
|
}
|
|
398
303
|
return years;
|
|
399
304
|
}
|
|
400
|
-
|
|
401
|
-
// src/mutation.ts
|
|
402
|
-
var import_date10 = require("@internationalized/date");
|
|
403
305
|
function getTodayDate(timeZone) {
|
|
404
|
-
return
|
|
306
|
+
return date.today(timeZone ?? date.getLocalTimeZone());
|
|
405
307
|
}
|
|
406
308
|
function getNextDay(date) {
|
|
407
309
|
return date.add({ days: 1 });
|
|
@@ -415,8 +317,8 @@ function setMonth(date, month) {
|
|
|
415
317
|
function setYear(date, year) {
|
|
416
318
|
return date.set({ year });
|
|
417
319
|
}
|
|
418
|
-
function setCalendar(date, calendar) {
|
|
419
|
-
return
|
|
320
|
+
function setCalendar(date$1, calendar) {
|
|
321
|
+
return date.toCalendar(date.toCalendarDateTime(date$1), calendar);
|
|
420
322
|
}
|
|
421
323
|
function setDate(date, startDate, isDateUnavailable2, locale, minValue, maxValue) {
|
|
422
324
|
let result;
|
|
@@ -435,9 +337,6 @@ function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable2) {
|
|
|
435
337
|
return date;
|
|
436
338
|
}
|
|
437
339
|
}
|
|
438
|
-
|
|
439
|
-
// src/pagination.ts
|
|
440
|
-
var import_date11 = require("@internationalized/date");
|
|
441
340
|
function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
|
|
442
341
|
return function getDate(options) {
|
|
443
342
|
const { startDate, focusedDate } = options;
|
|
@@ -528,13 +427,13 @@ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minVal
|
|
|
528
427
|
}
|
|
529
428
|
if (visibleDuration.weeks) {
|
|
530
429
|
return adjust({
|
|
531
|
-
focusedDate:
|
|
430
|
+
focusedDate: date.startOfWeek(focusedDate, locale),
|
|
532
431
|
startDate
|
|
533
432
|
});
|
|
534
433
|
}
|
|
535
434
|
if (visibleDuration.months || visibleDuration.years) {
|
|
536
435
|
return adjust({
|
|
537
|
-
focusedDate:
|
|
436
|
+
focusedDate: date.startOfMonth(focusedDate),
|
|
538
437
|
startDate
|
|
539
438
|
});
|
|
540
439
|
}
|
|
@@ -551,13 +450,13 @@ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue
|
|
|
551
450
|
if (visibleDuration.weeks) {
|
|
552
451
|
return adjust({
|
|
553
452
|
//@ts-expect-error - endOfWeek is loosely typed
|
|
554
|
-
focusedDate:
|
|
453
|
+
focusedDate: date.endOfWeek(focusedDate, locale),
|
|
555
454
|
startDate
|
|
556
455
|
});
|
|
557
456
|
}
|
|
558
457
|
if (visibleDuration.months || visibleDuration.years) {
|
|
559
458
|
return adjust({
|
|
560
|
-
focusedDate:
|
|
459
|
+
focusedDate: date.endOfMonth(focusedDate),
|
|
561
460
|
startDate
|
|
562
461
|
});
|
|
563
462
|
}
|
|
@@ -611,9 +510,6 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
611
510
|
}
|
|
612
511
|
}
|
|
613
512
|
|
|
614
|
-
// src/parse-date.ts
|
|
615
|
-
var import_date12 = require("@internationalized/date");
|
|
616
|
-
|
|
617
513
|
// src/normalize-year.ts
|
|
618
514
|
var FUTURE_YEAR_COERCION = 10;
|
|
619
515
|
function normalizeYear(year) {
|
|
@@ -635,9 +531,9 @@ function normalizeYear(year) {
|
|
|
635
531
|
var isValidYear = (year) => year != null && year.length === 4;
|
|
636
532
|
var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
637
533
|
var isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
638
|
-
function parseDateString(date, locale, timeZone) {
|
|
534
|
+
function parseDateString(date$1, locale, timeZone) {
|
|
639
535
|
const regex = createRegex(locale, timeZone);
|
|
640
|
-
let { year, month, day } = extract(regex, date) ?? {};
|
|
536
|
+
let { year, month, day } = extract(regex, date$1) ?? {};
|
|
641
537
|
const hasMatch = year != null || month != null || day != null;
|
|
642
538
|
if (hasMatch) {
|
|
643
539
|
const curr = /* @__PURE__ */ new Date();
|
|
@@ -649,16 +545,16 @@ function parseDateString(date, locale, timeZone) {
|
|
|
649
545
|
year = normalizeYear(year);
|
|
650
546
|
}
|
|
651
547
|
if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) {
|
|
652
|
-
return new
|
|
548
|
+
return new date.CalendarDate(+year, +month, +day);
|
|
653
549
|
}
|
|
654
|
-
const time = Date.parse(date);
|
|
550
|
+
const time = Date.parse(date$1);
|
|
655
551
|
if (!isNaN(time)) {
|
|
656
552
|
const date2 = new Date(time);
|
|
657
|
-
return new
|
|
553
|
+
return new date.CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
658
554
|
}
|
|
659
555
|
}
|
|
660
556
|
function createRegex(locale, timeZone) {
|
|
661
|
-
const formatter = new
|
|
557
|
+
const formatter = new date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
662
558
|
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
663
559
|
return parts.map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
|
|
664
560
|
}
|
|
@@ -680,20 +576,17 @@ function extract(pattern, str) {
|
|
|
680
576
|
return acc;
|
|
681
577
|
}, {});
|
|
682
578
|
}
|
|
683
|
-
|
|
684
|
-
// src/preset.ts
|
|
685
|
-
var import_date13 = require("@internationalized/date");
|
|
686
579
|
function getDateRangePreset(preset, locale, timeZone) {
|
|
687
|
-
const today4 =
|
|
580
|
+
const today4 = date.now(timeZone);
|
|
688
581
|
switch (preset) {
|
|
689
582
|
case "thisWeek":
|
|
690
|
-
return [
|
|
583
|
+
return [date.startOfWeek(today4, locale), date.endOfWeek(today4, locale)];
|
|
691
584
|
case "thisMonth":
|
|
692
|
-
return [
|
|
585
|
+
return [date.startOfMonth(today4), today4];
|
|
693
586
|
case "thisQuarter":
|
|
694
|
-
return [
|
|
587
|
+
return [date.startOfMonth(today4).add({ months: -today4.month % 3 }), today4];
|
|
695
588
|
case "thisYear":
|
|
696
|
-
return [
|
|
589
|
+
return [date.startOfYear(today4), today4];
|
|
697
590
|
case "last3Days":
|
|
698
591
|
return [today4.add({ days: -2 }), today4];
|
|
699
592
|
case "last7Days":
|
|
@@ -705,70 +598,67 @@ function getDateRangePreset(preset, locale, timeZone) {
|
|
|
705
598
|
case "last90Days":
|
|
706
599
|
return [today4.add({ days: -89 }), today4];
|
|
707
600
|
case "lastMonth":
|
|
708
|
-
return [
|
|
601
|
+
return [date.startOfMonth(today4.add({ months: -1 })), date.endOfMonth(today4.add({ months: -1 }))];
|
|
709
602
|
case "lastQuarter":
|
|
710
603
|
return [
|
|
711
|
-
|
|
712
|
-
|
|
604
|
+
date.startOfMonth(today4.add({ months: -today4.month % 3 - 3 })),
|
|
605
|
+
date.endOfMonth(today4.add({ months: -today4.month % 3 - 1 }))
|
|
713
606
|
];
|
|
714
607
|
case "lastWeek":
|
|
715
|
-
return [
|
|
608
|
+
return [date.startOfWeek(today4, locale).add({ weeks: -1 }), date.endOfWeek(today4, locale).add({ weeks: -1 })];
|
|
716
609
|
case "lastYear":
|
|
717
|
-
return [
|
|
610
|
+
return [date.startOfYear(today4.add({ years: -1 })), date.endOfYear(today4.add({ years: -1 }))];
|
|
718
611
|
default:
|
|
719
612
|
throw new Error(`Invalid date range preset: ${preset}`);
|
|
720
613
|
}
|
|
721
614
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
setYear
|
|
773
|
-
});
|
|
774
|
-
//# sourceMappingURL=index.js.map
|
|
615
|
+
|
|
616
|
+
exports.alignCenter = alignCenter;
|
|
617
|
+
exports.alignDate = alignDate;
|
|
618
|
+
exports.alignEnd = alignEnd;
|
|
619
|
+
exports.alignStart = alignStart;
|
|
620
|
+
exports.alignStartDate = alignStartDate;
|
|
621
|
+
exports.constrainStart = constrainStart;
|
|
622
|
+
exports.constrainValue = constrainValue;
|
|
623
|
+
exports.formatRange = formatRange;
|
|
624
|
+
exports.formatSelectedDate = formatSelectedDate;
|
|
625
|
+
exports.formatVisibleRange = formatVisibleRange;
|
|
626
|
+
exports.getAdjustedDateFn = getAdjustedDateFn;
|
|
627
|
+
exports.getCustomWeeksInMonth = getCustomWeeksInMonth;
|
|
628
|
+
exports.getDateRangePreset = getDateRangePreset;
|
|
629
|
+
exports.getDayFormatter = getDayFormatter;
|
|
630
|
+
exports.getDaysInWeek = getDaysInWeek;
|
|
631
|
+
exports.getDecadeRange = getDecadeRange;
|
|
632
|
+
exports.getEndDate = getEndDate;
|
|
633
|
+
exports.getMonthDays = getMonthDays;
|
|
634
|
+
exports.getMonthFormatter = getMonthFormatter;
|
|
635
|
+
exports.getMonthNames = getMonthNames;
|
|
636
|
+
exports.getNextDay = getNextDay;
|
|
637
|
+
exports.getNextPage = getNextPage;
|
|
638
|
+
exports.getNextRow = getNextRow;
|
|
639
|
+
exports.getNextSection = getNextSection;
|
|
640
|
+
exports.getPreviousAvailableDate = getPreviousAvailableDate;
|
|
641
|
+
exports.getPreviousDay = getPreviousDay;
|
|
642
|
+
exports.getPreviousPage = getPreviousPage;
|
|
643
|
+
exports.getPreviousRow = getPreviousRow;
|
|
644
|
+
exports.getPreviousSection = getPreviousSection;
|
|
645
|
+
exports.getSectionEnd = getSectionEnd;
|
|
646
|
+
exports.getSectionStart = getSectionStart;
|
|
647
|
+
exports.getTodayDate = getTodayDate;
|
|
648
|
+
exports.getUnitDuration = getUnitDuration;
|
|
649
|
+
exports.getWeekDays = getWeekDays;
|
|
650
|
+
exports.getWeekdayFormats = getWeekdayFormats;
|
|
651
|
+
exports.getYearsRange = getYearsRange;
|
|
652
|
+
exports.isDateDisabled = isDateDisabled;
|
|
653
|
+
exports.isDateEqual = isDateEqual;
|
|
654
|
+
exports.isDateInvalid = isDateInvalid;
|
|
655
|
+
exports.isDateOutsideVisibleRange = isDateOutsideVisibleRange;
|
|
656
|
+
exports.isDateUnavailable = isDateUnavailable;
|
|
657
|
+
exports.isNextVisibleRangeInvalid = isNextVisibleRangeInvalid;
|
|
658
|
+
exports.isPreviousVisibleRangeInvalid = isPreviousVisibleRangeInvalid;
|
|
659
|
+
exports.isTodayDate = isTodayDate;
|
|
660
|
+
exports.parseDateString = parseDateString;
|
|
661
|
+
exports.setCalendar = setCalendar;
|
|
662
|
+
exports.setDate = setDate;
|
|
663
|
+
exports.setMonth = setMonth;
|
|
664
|
+
exports.setYear = setYear;
|