@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.
Files changed (61) hide show
  1. package/dist/align.d.mts +8 -0
  2. package/dist/align.d.ts +8 -0
  3. package/dist/align.js +52 -0
  4. package/dist/align.mjs +26 -0
  5. package/dist/assertion.d.mts +10 -0
  6. package/dist/assertion.d.ts +10 -0
  7. package/dist/assertion.js +58 -0
  8. package/dist/assertion.mjs +29 -0
  9. package/dist/constrain.d.mts +9 -0
  10. package/dist/constrain.d.ts +9 -0
  11. package/dist/constrain.js +109 -0
  12. package/dist/constrain.mjs +87 -0
  13. package/dist/date-month.d.mts +23 -0
  14. package/dist/date-month.d.ts +23 -0
  15. package/dist/date-month.js +131 -0
  16. package/dist/date-month.mjs +105 -0
  17. package/dist/date-year.d.mts +14 -0
  18. package/dist/date-year.d.ts +14 -0
  19. package/dist/date-year.js +72 -0
  20. package/dist/date-year.mjs +44 -0
  21. package/dist/duration.d.mts +13 -0
  22. package/dist/duration.d.ts +13 -0
  23. package/dist/duration.js +42 -0
  24. package/dist/duration.mjs +16 -0
  25. package/dist/format.d.mts +8 -0
  26. package/dist/format.d.ts +8 -0
  27. package/dist/format.js +83 -0
  28. package/dist/format.mjs +56 -0
  29. package/dist/formatter.d.mts +6 -0
  30. package/dist/formatter.d.ts +6 -0
  31. package/dist/formatter.js +55 -0
  32. package/dist/formatter.mjs +29 -0
  33. package/dist/get-era-format.d.mts +6 -0
  34. package/dist/get-era-format.d.ts +6 -0
  35. package/dist/get-era-format.js +37 -0
  36. package/dist/get-era-format.mjs +12 -0
  37. package/dist/index.d.mts +14 -103
  38. package/dist/index.d.ts +14 -103
  39. package/dist/index.js +46 -637
  40. package/dist/index.mjs +13 -591
  41. package/dist/mutation.d.mts +10 -0
  42. package/dist/mutation.d.ts +10 -0
  43. package/dist/mutation.js +62 -0
  44. package/dist/mutation.mjs +39 -0
  45. package/dist/pagination.d.mts +21 -0
  46. package/dist/pagination.d.ts +21 -0
  47. package/dist/pagination.js +220 -0
  48. package/dist/pagination.mjs +187 -0
  49. package/dist/parse-date.d.mts +6 -0
  50. package/dist/parse-date.d.ts +6 -0
  51. package/dist/parse-date.js +79 -0
  52. package/dist/parse-date.mjs +54 -0
  53. package/dist/preset.d.mts +6 -0
  54. package/dist/preset.d.ts +6 -0
  55. package/dist/preset.js +66 -0
  56. package/dist/preset.mjs +50 -0
  57. package/dist/types.d.mts +23 -0
  58. package/dist/types.d.ts +23 -0
  59. package/dist/types.js +18 -0
  60. package/dist/types.mjs +0 -0
  61. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,637 +1,46 @@
1
- 'use strict';
2
-
3
- var date = require('@internationalized/date');
4
-
5
- // src/constrain.ts
6
- function alignCenter(date, duration, locale, min, max) {
7
- const halfDuration = {};
8
- for (let prop in duration) {
9
- const key = prop;
10
- const value = duration[key];
11
- if (value == null) continue;
12
- halfDuration[key] = Math.floor(value / 2);
13
- if (halfDuration[key] > 0 && value % 2 === 0) {
14
- halfDuration[key]--;
15
- }
16
- }
17
- const aligned = alignStart(date, duration, locale).subtract(halfDuration);
18
- return constrainStart(date, aligned, duration, locale, min, max);
19
- }
20
- function alignStart(date$1, duration, locale, min, max) {
21
- let aligned = date$1;
22
- if (duration.years) {
23
- aligned = date.startOfYear(date$1);
24
- } else if (duration.months) {
25
- aligned = date.startOfMonth(date$1);
26
- } else if (duration.weeks) {
27
- aligned = date.startOfWeek(date$1, locale);
28
- }
29
- return constrainStart(date$1, aligned, duration, locale, min, max);
30
- }
31
- function alignEnd(date, duration, locale, min, max) {
32
- let d = { ...duration };
33
- if (d.days) {
34
- d.days--;
35
- } else if (d.weeks) {
36
- d.weeks--;
37
- } else if (d.months) {
38
- d.months--;
39
- } else if (d.years) {
40
- d.years--;
41
- }
42
- let aligned = alignStart(date, duration, locale).subtract(d);
43
- return constrainStart(date, aligned, duration, locale, min, max);
44
- }
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));
48
- }
49
- if (max && date$1.compare(max) <= 0) {
50
- aligned = date.minDate(aligned, alignEnd(date.toCalendarDate(max), duration, locale));
51
- }
52
- return aligned;
53
- }
54
- function constrainValue(date$1, minValue, maxValue) {
55
- const dateOnly = date.toCalendarDate(date$1);
56
- const minOnly = minValue ? date.toCalendarDate(minValue) : void 0;
57
- const maxOnly = maxValue ? date.toCalendarDate(maxValue) : void 0;
58
- let constrainedDateOnly = dateOnly;
59
- if (minOnly) {
60
- constrainedDateOnly = date.maxDate(constrainedDateOnly, minOnly);
61
- }
62
- if (maxOnly) {
63
- constrainedDateOnly = date.minDate(constrainedDateOnly, maxOnly);
64
- }
65
- if (constrainedDateOnly.compare(dateOnly) === 0) {
66
- return date$1;
67
- }
68
- if ("hour" in date$1) {
69
- return date$1.set({
70
- year: constrainedDateOnly.year,
71
- month: constrainedDateOnly.month,
72
- day: constrainedDateOnly.day
73
- });
74
- }
75
- return constrainedDateOnly;
76
- }
77
-
78
- // src/align.ts
79
- function alignDate(date, alignment, duration, locale, min, max) {
80
- switch (alignment) {
81
- case "start":
82
- return alignStart(date, duration, locale, min, max);
83
- case "end":
84
- return alignEnd(date, duration, locale, min, max);
85
- case "center":
86
- default:
87
- return alignCenter(date, duration, locale, min, max);
88
- }
89
- }
90
- function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
91
- if (date.compare(startDate) < 0) {
92
- return alignEnd(date, duration, locale, min, max);
93
- }
94
- if (date.compare(endDate) > 0) {
95
- return alignStart(date, duration, locale, min, max);
96
- }
97
- return startDate;
98
- }
99
- function isDateEqual(dateA, dateB) {
100
- if (dateA == null || dateB == null) return dateA === dateB;
101
- return date.isSameDay(dateA, dateB);
102
- }
103
- function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
104
- if (!date) return false;
105
- if (isUnavailable?.(date, locale)) return true;
106
- return isDateOutsideRange(date, minValue, maxValue);
107
- }
108
- function isDateOutsideRange(date, startDate, endDate) {
109
- return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
110
- }
111
- function isPreviousRangeInvalid(startDate, minValue, maxValue) {
112
- const prevDate = startDate.subtract({ days: 1 });
113
- return date.isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
114
- }
115
- function isNextRangeInvalid(endDate, minValue, maxValue) {
116
- const nextDate = endDate.add({ days: 1 });
117
- return date.isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
118
- }
119
-
120
- // src/duration.ts
121
- function getUnitDuration(duration) {
122
- let clone = { ...duration };
123
- for (let key in clone) clone[key] = 1;
124
- return clone;
125
- }
126
- function getEndDate(startDate, duration) {
127
- let clone = { ...duration };
128
- if (clone.days) clone.days--;
129
- else clone.days = -1;
130
- return startDate.add(clone);
131
- }
132
-
133
- // src/get-era-format.ts
134
- function getEraFormat(date) {
135
- return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
136
- }
137
-
138
- // src/formatter.ts
139
- function getDayFormatter(locale, timeZone) {
140
- const date$1 = date.toCalendarDateTime(date.today(timeZone));
141
- return new date.DateFormatter(locale, {
142
- weekday: "long",
143
- month: "long",
144
- year: "numeric",
145
- day: "numeric",
146
- era: getEraFormat(date$1),
147
- timeZone
148
- });
149
- }
150
- function getMonthFormatter(locale, timeZone) {
151
- const date$1 = date.today(timeZone);
152
- return new date.DateFormatter(locale, {
153
- month: "long",
154
- year: "numeric",
155
- era: getEraFormat(date$1),
156
- calendar: date$1?.calendar.identifier,
157
- timeZone
158
- });
159
- }
160
-
161
- // src/format.ts
162
- function formatRange(startDate, endDate, formatter, toString, timeZone) {
163
- let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
164
- let separatorIndex = -1;
165
- for (let i = 0; i < parts.length; i++) {
166
- let part = parts[i];
167
- if (part.source === "shared" && part.type === "literal") {
168
- separatorIndex = i;
169
- } else if (part.source === "endRange") {
170
- break;
171
- }
172
- }
173
- let start = "";
174
- let end = "";
175
- for (let i = 0; i < parts.length; i++) {
176
- if (i < separatorIndex) {
177
- start += parts[i].value;
178
- } else if (i > separatorIndex) {
179
- end += parts[i].value;
180
- }
181
- }
182
- return toString(start, end);
183
- }
184
- function formatSelectedDate(startDate, endDate, locale, timeZone) {
185
- if (!startDate) return "";
186
- let start = startDate;
187
- let end = endDate ?? startDate;
188
- let formatter = getDayFormatter(locale, timeZone);
189
- if (date.isSameDay(start, end)) {
190
- return formatter.format(start.toDate(timeZone));
191
- }
192
- return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
193
- }
194
- function formatVisibleRange(startDate, endDate, locale, timeZone) {
195
- const start = startDate;
196
- const end = endDate ?? startDate;
197
- const dayFormatter = getDayFormatter(locale, timeZone);
198
- if (!date.isSameDay(start, date.startOfMonth(start))) {
199
- return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
200
- }
201
- const monthFormatter = getMonthFormatter(locale, timeZone);
202
- if (date.isSameDay(end, date.endOfMonth(start))) {
203
- return monthFormatter.format(start.toDate(timeZone));
204
- }
205
- if (date.isSameDay(end, date.endOfMonth(end))) {
206
- return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
207
- }
208
- return "";
209
- }
210
- var daysOfTheWeek = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
211
- function normalizeFirstDayOfWeek(firstDayOfWeek) {
212
- return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
213
- }
214
- function getStartOfWeek(date$1, locale, firstDayOfWeek) {
215
- const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
216
- return date.startOfWeek(date$1, locale, firstDay);
217
- }
218
- function getEndOfWeek(date$1, locale, firstDayOfWeek = 0) {
219
- const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
220
- return date.endOfWeek(date$1, locale, firstDay);
221
- }
222
- function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
223
- const weekDate = from.add({ weeks: weekIndex });
224
- const dates = [];
225
- let date$1 = getStartOfWeek(weekDate, locale, firstDayOfWeek);
226
- while (dates.length < 7) {
227
- dates.push(date$1);
228
- let nextDate = date$1.add({ days: 1 });
229
- if (date.isSameDay(date$1, nextDate)) break;
230
- date$1 = nextDate;
231
- }
232
- return dates;
233
- }
234
- function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
235
- const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
236
- const monthWeeks = numOfWeeks ?? date.getWeeksInMonth(from, locale, firstDay);
237
- const weeks = [...new Array(monthWeeks).keys()];
238
- return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
239
- }
240
- function getWeekdayFormats(locale, timeZone) {
241
- const longFormat = new date.DateFormatter(locale, { weekday: "long", timeZone });
242
- const shortFormat = new date.DateFormatter(locale, { weekday: "short", timeZone });
243
- const narrowFormat = new date.DateFormatter(locale, { weekday: "narrow", timeZone });
244
- return (value) => {
245
- const date = value instanceof Date ? value : value.toDate(timeZone);
246
- return {
247
- value,
248
- short: shortFormat.format(date),
249
- long: longFormat.format(date),
250
- narrow: narrowFormat.format(date)
251
- };
252
- };
253
- }
254
- function getWeekDays(date, startOfWeekProp, timeZone, locale) {
255
- const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
256
- const weeks = [...new Array(7).keys()];
257
- const format = getWeekdayFormats(locale, timeZone);
258
- return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
259
- }
260
- function getMonthNames(locale, format = "long") {
261
- const date = new Date(2021, 0, 1);
262
- const monthNames = [];
263
- for (let i = 0; i < 12; i++) {
264
- monthNames.push(date.toLocaleString(locale, { month: format }));
265
- date.setMonth(date.getMonth() + 1);
266
- }
267
- return monthNames;
268
- }
269
- function getWeekOfYear(date$1, locale) {
270
- const mondayOfWeek = date.startOfWeek(date$1, locale, "mon");
271
- const year = mondayOfWeek.year;
272
- const jan4 = mondayOfWeek.set({ month: 1, day: 4 });
273
- const week1Monday = date.startOfWeek(jan4, locale, "mon");
274
- const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
275
- const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
276
- if (julianMonday >= julianWeek1) {
277
- return 1 + Math.floor((julianMonday - julianWeek1) / 7);
278
- }
279
- const prevJan4 = mondayOfWeek.set({ year: year - 1, month: 1, day: 4 });
280
- const prevWeek1Monday = date.startOfWeek(prevJan4, locale, "mon");
281
- const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
282
- return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
283
- }
284
-
285
- // src/date-year.ts
286
- function getYearsRange(range) {
287
- const years = [];
288
- for (let year = range.from; year <= range.to; year += 1) years.push(year);
289
- return years;
290
- }
291
- var FUTURE_YEAR_COERCION = 10;
292
- function normalizeYear(year) {
293
- if (!year) return;
294
- if (year.length === 3) return year.padEnd(4, "0");
295
- if (year.length === 2) {
296
- const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
297
- const currentCentury = Math.floor(currentYear / 100) * 100;
298
- const twoDigitYear = parseInt(year.slice(-2), 10);
299
- const fullYear = currentCentury + twoDigitYear;
300
- return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
301
- }
302
- return year;
303
- }
304
- function getDecadeRange(year, opts) {
305
- const chunkSize = opts?.strict ? 10 : 12;
306
- const computedYear = year - year % 10;
307
- const years = [];
308
- for (let i = 0; i < chunkSize; i += 1) {
309
- const value = computedYear + i;
310
- years.push(value);
311
- }
312
- return years;
313
- }
314
- function getTodayDate(timeZone) {
315
- return date.today(timeZone ?? date.getLocalTimeZone());
316
- }
317
- function setCalendar(date$1, calendar) {
318
- return date.toCalendar(date.toCalendarDateTime(date$1), calendar);
319
- }
320
- function setDate(date, startDate, isDateUnavailable2, locale, minValue, maxValue) {
321
- let result;
322
- result = constrainValue(date, minValue, maxValue);
323
- result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable2);
324
- return result;
325
- }
326
- function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable2) {
327
- if (!isDateUnavailable2) {
328
- return date;
329
- }
330
- while (date.compare(minValue) >= 0 && isDateUnavailable2(date, locale)) {
331
- date = date.subtract({ days: 1 });
332
- }
333
- if (date.compare(minValue) >= 0) {
334
- return date;
335
- }
336
- }
337
- function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
338
- return function getDate(options) {
339
- const { startDate, focusedDate } = options;
340
- const endDate = getEndDate(startDate, visibleDuration);
341
- if (isDateOutsideRange(focusedDate, minValue, maxValue)) {
342
- return {
343
- startDate,
344
- focusedDate: constrainValue(focusedDate, minValue, maxValue),
345
- endDate
346
- };
347
- }
348
- if (focusedDate.compare(startDate) < 0) {
349
- return {
350
- startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
351
- focusedDate: constrainValue(focusedDate, minValue, maxValue),
352
- endDate
353
- };
354
- }
355
- if (focusedDate.compare(endDate) > 0) {
356
- return {
357
- startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
358
- endDate,
359
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
360
- };
361
- }
362
- return {
363
- startDate,
364
- endDate,
365
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
366
- };
367
- };
368
- }
369
- function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
370
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
371
- const start = startDate.add(visibleDuration);
372
- return adjust({
373
- focusedDate: focusedDate.add(visibleDuration),
374
- startDate: alignStart(
375
- constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
376
- visibleDuration,
377
- locale
378
- )
379
- });
380
- }
381
- function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
382
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
383
- let start = startDate.subtract(visibleDuration);
384
- return adjust({
385
- focusedDate: focusedDate.subtract(visibleDuration),
386
- startDate: alignStart(
387
- constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
388
- visibleDuration,
389
- locale
390
- )
391
- });
392
- }
393
- function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
394
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
395
- if (visibleDuration.days) {
396
- return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
397
- }
398
- if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
399
- return adjust({
400
- focusedDate: focusedDate.add({ weeks: 1 }),
401
- startDate
402
- });
403
- }
404
- }
405
- function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
406
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
407
- if (visibleDuration.days) {
408
- return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
409
- }
410
- if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
411
- return adjust({
412
- focusedDate: focusedDate.subtract({ weeks: 1 }),
413
- startDate
414
- });
415
- }
416
- }
417
- function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
418
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
419
- if (visibleDuration.days) {
420
- return adjust({
421
- focusedDate: startDate,
422
- startDate
423
- });
424
- }
425
- if (visibleDuration.weeks) {
426
- return adjust({
427
- focusedDate: date.startOfWeek(focusedDate, locale),
428
- startDate
429
- });
430
- }
431
- if (visibleDuration.months || visibleDuration.years) {
432
- return adjust({
433
- focusedDate: date.startOfMonth(focusedDate),
434
- startDate
435
- });
436
- }
437
- }
438
- function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
439
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
440
- const endDate = getEndDate(startDate, visibleDuration);
441
- if (visibleDuration.days) {
442
- return adjust({
443
- focusedDate: endDate,
444
- startDate
445
- });
446
- }
447
- if (visibleDuration.weeks) {
448
- return adjust({
449
- focusedDate: date.endOfWeek(focusedDate, locale),
450
- startDate
451
- });
452
- }
453
- if (visibleDuration.months || visibleDuration.years) {
454
- return adjust({
455
- focusedDate: date.endOfMonth(focusedDate),
456
- startDate
457
- });
458
- }
459
- }
460
- function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
461
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
462
- if (!larger && !visibleDuration.days) {
463
- return adjust({
464
- focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
465
- startDate
466
- });
467
- }
468
- if (visibleDuration.days) {
469
- return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
470
- }
471
- if (visibleDuration.weeks) {
472
- return adjust({
473
- focusedDate: focusedDate.add({ months: 1 }),
474
- startDate
475
- });
476
- }
477
- if (visibleDuration.months || visibleDuration.years) {
478
- return adjust({
479
- focusedDate: focusedDate.add({ years: 1 }),
480
- startDate
481
- });
482
- }
483
- }
484
- function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
485
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
486
- if (!larger && !visibleDuration.days) {
487
- return adjust({
488
- focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
489
- startDate
490
- });
491
- }
492
- if (visibleDuration.days) {
493
- return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
494
- }
495
- if (visibleDuration.weeks) {
496
- return adjust({
497
- focusedDate: focusedDate.subtract({ months: 1 }),
498
- startDate
499
- });
500
- }
501
- if (visibleDuration.months || visibleDuration.years) {
502
- return adjust({
503
- focusedDate: focusedDate.subtract({ years: 1 }),
504
- startDate
505
- });
506
- }
507
- }
508
- var isValidYear = (year) => year != null && year.length === 4;
509
- var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
510
- var isValidDay = (day) => day != null && parseFloat(day) <= 31;
511
- function parseDateString(date$1, locale, timeZone) {
512
- const regex = createRegex(locale, timeZone);
513
- let { year, month, day } = extract(regex, date$1) ?? {};
514
- const hasMatch = year != null || month != null || day != null;
515
- if (hasMatch) {
516
- const curr = /* @__PURE__ */ new Date();
517
- year || (year = curr.getFullYear().toString());
518
- month || (month = (curr.getMonth() + 1).toString());
519
- day || (day = curr.getDate().toString());
520
- }
521
- if (!isValidYear(year)) {
522
- year = normalizeYear(year);
523
- }
524
- if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) {
525
- return new date.CalendarDate(+year, +month, +day);
526
- }
527
- const time = Date.parse(date$1);
528
- if (!isNaN(time)) {
529
- const date2 = new Date(time);
530
- return new date.CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
531
- }
532
- }
533
- function createRegex(locale, timeZone) {
534
- const formatter = new date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
535
- const parts = formatter.formatToParts(new Date(2e3, 11, 25));
536
- return parts.map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
537
- }
538
- function extract(pattern, str) {
539
- const matches = str.match(pattern);
540
- return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
541
- const groupMatches = group.match(/<(.+)>/);
542
- if (!groupMatches || groupMatches.length <= 0) {
543
- return null;
544
- }
545
- return group.match(/<(.+)>/)?.[1];
546
- }).reduce((acc, curr, index) => {
547
- if (!curr) return acc;
548
- if (matches && matches.length > index) {
549
- acc[curr] = matches[index + 1];
550
- } else {
551
- acc[curr] = null;
552
- }
553
- return acc;
554
- }, {});
555
- }
556
- function getDateRangePreset(preset, locale, timeZone) {
557
- const today3 = date.toCalendarDate(date.now(timeZone));
558
- switch (preset) {
559
- case "thisWeek":
560
- return [date.startOfWeek(today3, locale), date.endOfWeek(today3, locale)];
561
- case "thisMonth":
562
- return [date.startOfMonth(today3), today3];
563
- case "thisQuarter":
564
- return [date.startOfMonth(today3).add({ months: -((today3.month - 1) % 3) }), today3];
565
- case "thisYear":
566
- return [date.startOfYear(today3), today3];
567
- case "last3Days":
568
- return [today3.add({ days: -2 }), today3];
569
- case "last7Days":
570
- return [today3.add({ days: -6 }), today3];
571
- case "last14Days":
572
- return [today3.add({ days: -13 }), today3];
573
- case "last30Days":
574
- return [today3.add({ days: -29 }), today3];
575
- case "last90Days":
576
- return [today3.add({ days: -89 }), today3];
577
- case "lastMonth":
578
- return [date.startOfMonth(today3.add({ months: -1 })), date.endOfMonth(today3.add({ months: -1 }))];
579
- case "lastQuarter":
580
- return [
581
- date.startOfMonth(today3.add({ months: -((today3.month - 1) % 3) - 3 })),
582
- date.endOfMonth(today3.add({ months: -((today3.month - 1) % 3) - 1 }))
583
- ];
584
- case "lastWeek":
585
- return [date.startOfWeek(today3, locale).add({ weeks: -1 }), date.endOfWeek(today3, locale).add({ weeks: -1 })];
586
- case "lastYear":
587
- return [date.startOfYear(today3.add({ years: -1 })), date.endOfYear(today3.add({ years: -1 }))];
588
- default:
589
- throw new Error(`Invalid date range preset: ${preset}`);
590
- }
591
- }
592
-
593
- exports.alignCenter = alignCenter;
594
- exports.alignDate = alignDate;
595
- exports.alignEnd = alignEnd;
596
- exports.alignStart = alignStart;
597
- exports.alignStartDate = alignStartDate;
598
- exports.constrainStart = constrainStart;
599
- exports.constrainValue = constrainValue;
600
- exports.formatRange = formatRange;
601
- exports.formatSelectedDate = formatSelectedDate;
602
- exports.formatVisibleRange = formatVisibleRange;
603
- exports.getAdjustedDateFn = getAdjustedDateFn;
604
- exports.getDateRangePreset = getDateRangePreset;
605
- exports.getDayFormatter = getDayFormatter;
606
- exports.getDaysInWeek = getDaysInWeek;
607
- exports.getDecadeRange = getDecadeRange;
608
- exports.getEndDate = getEndDate;
609
- exports.getEndOfWeek = getEndOfWeek;
610
- exports.getMonthDays = getMonthDays;
611
- exports.getMonthFormatter = getMonthFormatter;
612
- exports.getMonthNames = getMonthNames;
613
- exports.getNextPage = getNextPage;
614
- exports.getNextRow = getNextRow;
615
- exports.getNextSection = getNextSection;
616
- exports.getPreviousAvailableDate = getPreviousAvailableDate;
617
- exports.getPreviousPage = getPreviousPage;
618
- exports.getPreviousRow = getPreviousRow;
619
- exports.getPreviousSection = getPreviousSection;
620
- exports.getSectionEnd = getSectionEnd;
621
- exports.getSectionStart = getSectionStart;
622
- exports.getStartOfWeek = getStartOfWeek;
623
- exports.getTodayDate = getTodayDate;
624
- exports.getUnitDuration = getUnitDuration;
625
- exports.getWeekDays = getWeekDays;
626
- exports.getWeekOfYear = getWeekOfYear;
627
- exports.getWeekdayFormats = getWeekdayFormats;
628
- exports.getYearsRange = getYearsRange;
629
- exports.isDateEqual = isDateEqual;
630
- exports.isDateOutsideRange = isDateOutsideRange;
631
- exports.isDateUnavailable = isDateUnavailable;
632
- exports.isNextRangeInvalid = isNextRangeInvalid;
633
- exports.isPreviousRangeInvalid = isPreviousRangeInvalid;
634
- exports.normalizeYear = normalizeYear;
635
- exports.parseDateString = parseDateString;
636
- exports.setCalendar = setCalendar;
637
- exports.setDate = setDate;
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/index.ts
18
+ var index_exports = {};
19
+ module.exports = __toCommonJS(index_exports);
20
+ __reExport(index_exports, require("./align.cjs"), module.exports);
21
+ __reExport(index_exports, require("./assertion.cjs"), module.exports);
22
+ __reExport(index_exports, require("./constrain.cjs"), module.exports);
23
+ __reExport(index_exports, require("./duration.cjs"), module.exports);
24
+ __reExport(index_exports, require("./format.cjs"), module.exports);
25
+ __reExport(index_exports, require("./formatter.cjs"), module.exports);
26
+ __reExport(index_exports, require("./date-month.cjs"), module.exports);
27
+ __reExport(index_exports, require("./date-year.cjs"), module.exports);
28
+ __reExport(index_exports, require("./mutation.cjs"), module.exports);
29
+ __reExport(index_exports, require("./pagination.cjs"), module.exports);
30
+ __reExport(index_exports, require("./parse-date.cjs"), module.exports);
31
+ __reExport(index_exports, require("./preset.cjs"), module.exports);
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ ...require("./align.cjs"),
35
+ ...require("./assertion.cjs"),
36
+ ...require("./constrain.cjs"),
37
+ ...require("./duration.cjs"),
38
+ ...require("./format.cjs"),
39
+ ...require("./formatter.cjs"),
40
+ ...require("./date-month.cjs"),
41
+ ...require("./date-year.cjs"),
42
+ ...require("./mutation.cjs"),
43
+ ...require("./pagination.cjs"),
44
+ ...require("./parse-date.cjs"),
45
+ ...require("./preset.cjs")
46
+ });