@zag-js/date-utils 0.10.4 → 0.11.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 (73) hide show
  1. package/dist/index.d.mts +145 -0
  2. package/dist/index.d.ts +145 -20
  3. package/dist/index.js +744 -74
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +687 -19
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +2 -2
  8. package/src/parse-date.ts +12 -9
  9. package/dist/align.d.ts +0 -4
  10. package/dist/align.js +0 -29
  11. package/dist/align.mjs +0 -24
  12. package/dist/assertion.d.ts +0 -10
  13. package/dist/assertion.js +0 -47
  14. package/dist/assertion.mjs +0 -36
  15. package/dist/constrain.d.ts +0 -6
  16. package/dist/constrain.js +0 -66
  17. package/dist/constrain.mjs +0 -58
  18. package/dist/duration.d.ts +0 -8
  19. package/dist/duration.js +0 -23
  20. package/dist/duration.mjs +0 -18
  21. package/dist/format-date.d.ts +0 -6
  22. package/dist/format-date.js +0 -57
  23. package/dist/format-date.mjs +0 -53
  24. package/dist/format-range.d.ts +0 -2
  25. package/dist/format-range.js +0 -28
  26. package/dist/format-range.mjs +0 -24
  27. package/dist/format-selected-date.d.ts +0 -2
  28. package/dist/format-selected-date.js +0 -19
  29. package/dist/format-selected-date.mjs +0 -15
  30. package/dist/format-visible-range.d.ts +0 -2
  31. package/dist/format-visible-range.js +0 -26
  32. package/dist/format-visible-range.mjs +0 -22
  33. package/dist/get-day-formatter.d.ts +0 -2
  34. package/dist/get-day-formatter.js +0 -20
  35. package/dist/get-day-formatter.mjs +0 -16
  36. package/dist/get-decade-range.d.ts +0 -1
  37. package/dist/get-decade-range.js +0 -15
  38. package/dist/get-decade-range.mjs +0 -11
  39. package/dist/get-end-of-week.d.ts +0 -2
  40. package/dist/get-era-format.d.ts +0 -2
  41. package/dist/get-era-format.js +0 -9
  42. package/dist/get-era-format.mjs +0 -5
  43. package/dist/get-month-days.d.ts +0 -3
  44. package/dist/get-month-days.js +0 -29
  45. package/dist/get-month-days.mjs +0 -24
  46. package/dist/get-month-formatter.d.ts +0 -2
  47. package/dist/get-month-formatter.js +0 -19
  48. package/dist/get-month-formatter.mjs +0 -15
  49. package/dist/get-month-names.d.ts +0 -1
  50. package/dist/get-month-names.js +0 -15
  51. package/dist/get-month-names.mjs +0 -11
  52. package/dist/get-start-of-week.d.ts +0 -2
  53. package/dist/get-start-of-week.js +0 -13
  54. package/dist/get-start-of-week.mjs +0 -9
  55. package/dist/get-week-days.d.ts +0 -7
  56. package/dist/get-week-days.js +0 -15
  57. package/dist/get-week-days.mjs +0 -11
  58. package/dist/get-weekday-formats.d.ts +0 -7
  59. package/dist/get-weekday-formats.js +0 -22
  60. package/dist/get-weekday-formats.mjs +0 -18
  61. package/dist/get-year-range.d.ts +0 -5
  62. package/dist/get-year-range.js +0 -13
  63. package/dist/get-year-range.mjs +0 -9
  64. package/dist/mutation.d.ts +0 -10
  65. package/dist/mutation.js +0 -51
  66. package/dist/mutation.mjs +0 -40
  67. package/dist/pagination.d.ts +0 -49
  68. package/dist/pagination.js +0 -191
  69. package/dist/pagination.mjs +0 -179
  70. package/dist/parse-date.d.ts +0 -2
  71. package/dist/parse-date.js +0 -44
  72. package/dist/parse-date.mjs +0 -40
  73. package/dist/types.d.ts +0 -18
package/dist/index.js CHANGED
@@ -1,74 +1,744 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const align = require('./align.js');
6
- const assertion = require('./assertion.js');
7
- const constrain = require('./constrain.js');
8
- const duration = require('./duration.js');
9
- const formatDate = require('./format-date.js');
10
- const formatRange = require('./format-range.js');
11
- const formatSelectedDate = require('./format-selected-date.js');
12
- const formatVisibleRange = require('./format-visible-range.js');
13
- const getDayFormatter = require('./get-day-formatter.js');
14
- const getDecadeRange = require('./get-decade-range.js');
15
- const getMonthDays = require('./get-month-days.js');
16
- const getMonthFormatter = require('./get-month-formatter.js');
17
- const getMonthNames = require('./get-month-names.js');
18
- const getWeekDays = require('./get-week-days.js');
19
- const getWeekdayFormats = require('./get-weekday-formats.js');
20
- const getYearRange = require('./get-year-range.js');
21
- const mutation = require('./mutation.js');
22
- const pagination = require('./pagination.js');
23
- const parseDate = require('./parse-date.js');
24
-
25
-
26
-
27
- exports.alignDate = align.alignDate;
28
- exports.alignStartDate = align.alignStartDate;
29
- exports.isDateDisabled = assertion.isDateDisabled;
30
- exports.isDateEqual = assertion.isDateEqual;
31
- exports.isDateInvalid = assertion.isDateInvalid;
32
- exports.isDateOutsideVisibleRange = assertion.isDateOutsideVisibleRange;
33
- exports.isDateUnavailable = assertion.isDateUnavailable;
34
- exports.isNextVisibleRangeInvalid = assertion.isNextVisibleRangeInvalid;
35
- exports.isPreviousVisibleRangeInvalid = assertion.isPreviousVisibleRangeInvalid;
36
- exports.isTodayDate = assertion.isTodayDate;
37
- exports.alignCenter = constrain.alignCenter;
38
- exports.alignEnd = constrain.alignEnd;
39
- exports.alignStart = constrain.alignStart;
40
- exports.constrainStart = constrain.constrainStart;
41
- exports.constrainValue = constrain.constrainValue;
42
- exports.getEndDate = duration.getEndDate;
43
- exports.getUnitDuration = duration.getUnitDuration;
44
- exports.formatDate = formatDate.formatDate;
45
- exports.formatRange = formatRange.formatRange;
46
- exports.formatSelectedDate = formatSelectedDate.formatSelectedDate;
47
- exports.formatVisibleRange = formatVisibleRange.formatVisibleRange;
48
- exports.getDayFormatter = getDayFormatter.getDayFormatter;
49
- exports.getDecadeRange = getDecadeRange.getDecadeRange;
50
- exports.getDaysInWeek = getMonthDays.getDaysInWeek;
51
- exports.getMonthDays = getMonthDays.getMonthDays;
52
- exports.getMonthFormatter = getMonthFormatter.getMonthFormatter;
53
- exports.getMonthNames = getMonthNames.getMonthNames;
54
- exports.getWeekDays = getWeekDays.getWeekDays;
55
- exports.getWeekdayFormats = getWeekdayFormats.getWeekdayFormats;
56
- exports.getYearsRange = getYearRange.getYearsRange;
57
- exports.getNextDay = mutation.getNextDay;
58
- exports.getPreviousAvailableDate = mutation.getPreviousAvailableDate;
59
- exports.getPreviousDay = mutation.getPreviousDay;
60
- exports.getTodayDate = mutation.getTodayDate;
61
- exports.setCalendar = mutation.setCalendar;
62
- exports.setDate = mutation.setDate;
63
- exports.setMonth = mutation.setMonth;
64
- exports.setYear = mutation.setYear;
65
- exports.getAdjustedDateFn = pagination.getAdjustedDateFn;
66
- exports.getNextPage = pagination.getNextPage;
67
- exports.getNextRow = pagination.getNextRow;
68
- exports.getNextSection = pagination.getNextSection;
69
- exports.getPreviousPage = pagination.getPreviousPage;
70
- exports.getPreviousRow = pagination.getPreviousRow;
71
- exports.getPreviousSection = pagination.getPreviousSection;
72
- exports.getSectionEnd = pagination.getSectionEnd;
73
- exports.getSectionStart = pagination.getSectionStart;
74
- exports.parseDateString = parseDate.parseDateString;
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/index.ts
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
+ formatDate: () => formatDate,
31
+ formatRange: () => formatRange,
32
+ formatSelectedDate: () => formatSelectedDate,
33
+ formatVisibleRange: () => formatVisibleRange,
34
+ getAdjustedDateFn: () => getAdjustedDateFn,
35
+ getDayFormatter: () => getDayFormatter,
36
+ getDaysInWeek: () => getDaysInWeek,
37
+ getDecadeRange: () => getDecadeRange,
38
+ getEndDate: () => getEndDate,
39
+ getMonthDays: () => getMonthDays,
40
+ getMonthFormatter: () => getMonthFormatter,
41
+ getMonthNames: () => getMonthNames,
42
+ getNextDay: () => getNextDay,
43
+ getNextPage: () => getNextPage,
44
+ getNextRow: () => getNextRow,
45
+ getNextSection: () => getNextSection,
46
+ getPreviousAvailableDate: () => getPreviousAvailableDate,
47
+ getPreviousDay: () => getPreviousDay,
48
+ getPreviousPage: () => getPreviousPage,
49
+ getPreviousRow: () => getPreviousRow,
50
+ getPreviousSection: () => getPreviousSection,
51
+ getSectionEnd: () => getSectionEnd,
52
+ getSectionStart: () => getSectionStart,
53
+ getTodayDate: () => getTodayDate,
54
+ getUnitDuration: () => getUnitDuration,
55
+ getWeekDays: () => getWeekDays,
56
+ getWeekdayFormats: () => getWeekdayFormats,
57
+ getYearsRange: () => getYearsRange,
58
+ isDateDisabled: () => isDateDisabled,
59
+ isDateEqual: () => isDateEqual,
60
+ isDateInvalid: () => isDateInvalid,
61
+ isDateOutsideVisibleRange: () => isDateOutsideVisibleRange,
62
+ isDateUnavailable: () => isDateUnavailable,
63
+ isNextVisibleRangeInvalid: () => isNextVisibleRangeInvalid,
64
+ isPreviousVisibleRangeInvalid: () => isPreviousVisibleRangeInvalid,
65
+ isTodayDate: () => isTodayDate,
66
+ parseDateString: () => parseDateString,
67
+ setCalendar: () => setCalendar,
68
+ setDate: () => setDate,
69
+ setMonth: () => setMonth,
70
+ setYear: () => setYear
71
+ });
72
+ module.exports = __toCommonJS(src_exports);
73
+
74
+ // src/constrain.ts
75
+ var import_date = require("@internationalized/date");
76
+ function alignCenter(date, duration, locale, min, max) {
77
+ let halfDuration = {};
78
+ for (let key in duration) {
79
+ halfDuration[key] = Math.floor(duration[key] / 2);
80
+ if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
81
+ halfDuration[key]--;
82
+ }
83
+ }
84
+ let aligned = alignStart(date, duration, locale).subtract(halfDuration);
85
+ return constrainStart(date, aligned, duration, locale, min, max);
86
+ }
87
+ function alignStart(date, duration, locale, min, max) {
88
+ let aligned = date;
89
+ if (duration.years) {
90
+ aligned = (0, import_date.startOfYear)(date);
91
+ } else if (duration.months) {
92
+ aligned = (0, import_date.startOfMonth)(date);
93
+ } else if (duration.weeks) {
94
+ aligned = (0, import_date.startOfWeek)(date, locale);
95
+ }
96
+ return constrainStart(date, aligned, duration, locale, min, max);
97
+ }
98
+ function alignEnd(date, duration, locale, min, max) {
99
+ let d = { ...duration };
100
+ if (d.days) {
101
+ d.days--;
102
+ } else if (d.weeks) {
103
+ d.weeks--;
104
+ } else if (d.months) {
105
+ d.months--;
106
+ } else if (d.years) {
107
+ d.years--;
108
+ }
109
+ let aligned = alignStart(date, duration, locale).subtract(d);
110
+ return constrainStart(date, aligned, duration, locale, min, max);
111
+ }
112
+ function constrainStart(date, aligned, duration, locale, min, max) {
113
+ if (min && date.compare(min) >= 0) {
114
+ aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
115
+ }
116
+ if (max && date.compare(max) <= 0) {
117
+ aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
118
+ }
119
+ return aligned;
120
+ }
121
+ function constrainValue(date, minValue, maxValue) {
122
+ if (minValue) {
123
+ date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(minValue));
124
+ }
125
+ if (maxValue) {
126
+ date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(maxValue));
127
+ }
128
+ return date;
129
+ }
130
+
131
+ // src/align.ts
132
+ function alignDate(date, alignment, duration, locale, min, max) {
133
+ switch (alignment) {
134
+ case "start":
135
+ return alignStart(date, duration, locale, min, max);
136
+ case "end":
137
+ return alignEnd(date, duration, locale, min, max);
138
+ case "center":
139
+ default:
140
+ return alignCenter(date, duration, locale, min, max);
141
+ }
142
+ }
143
+ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
144
+ if (date.compare(startDate) < 0) {
145
+ return alignEnd(date, duration, locale, min, max);
146
+ }
147
+ if (date.compare(endDate) > 0) {
148
+ return alignStart(date, duration, locale, min, max);
149
+ }
150
+ return startDate;
151
+ }
152
+
153
+ // src/assertion.ts
154
+ var import_date2 = require("@internationalized/date");
155
+ function isTodayDate(date, timeZone) {
156
+ return (0, import_date2.isToday)(date, timeZone);
157
+ }
158
+ function isDateEqual(dateA, dateB) {
159
+ return dateB != null && (0, import_date2.isSameDay)(dateA, dateB);
160
+ }
161
+ function isDateInvalid(date, minValue, maxValue) {
162
+ return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
163
+ }
164
+ function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
165
+ return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(date, minValue, maxValue);
166
+ }
167
+ function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
168
+ if (!date) {
169
+ return false;
170
+ }
171
+ if (isUnavailable?.(date, locale)) {
172
+ return true;
173
+ }
174
+ return isDateInvalid(date, minValue, maxValue);
175
+ }
176
+ function isDateOutsideVisibleRange(date, startDate, endDate) {
177
+ return date.compare(startDate) < 0 || date.compare(endDate) > 0;
178
+ }
179
+ function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
180
+ const prevDate = startDate.subtract({ days: 1 });
181
+ return (0, import_date2.isSameDay)(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
182
+ }
183
+ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
184
+ const nextDate = endDate.add({ days: 1 });
185
+ return (0, import_date2.isSameDay)(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
186
+ }
187
+
188
+ // src/duration.ts
189
+ function getUnitDuration(duration) {
190
+ let d = { ...duration };
191
+ for (let key in d) {
192
+ d[key] = 1;
193
+ }
194
+ return d;
195
+ }
196
+ function getEndDate(startDate, duration) {
197
+ let d = { ...duration };
198
+ if (d.days) {
199
+ d.days--;
200
+ } else {
201
+ d.days = -1;
202
+ }
203
+ return startDate.add(d);
204
+ }
205
+
206
+ // src/format-date.ts
207
+ var import_date3 = require("@internationalized/date");
208
+ function createRegEx(sign) {
209
+ let symbols = "\\s|\\.|-|/|\\\\|,|\\$|\\!|\\?|:|;";
210
+ return new RegExp("(^|>|" + symbols + ")(" + sign + ")($|<|" + symbols + ")", "g");
211
+ }
212
+ function formatDate(value, formatString, locale, timeZone = "UTC") {
213
+ const datetime = (0, import_date3.toCalendarDateTime)(value);
214
+ const date = datetime.toDate(timeZone);
215
+ const formats = {
216
+ // Time in ms
217
+ T: date.getTime(),
218
+ // Minutes
219
+ m: date.toLocaleString(locale, { minute: "numeric" }),
220
+ mm: date.toLocaleString(locale, { minute: "2-digit" }),
221
+ // Seconds
222
+ s: date.toLocaleString(locale, { second: "numeric" }),
223
+ ss: date.toLocaleString(locale, { second: "2-digit" }),
224
+ // Hours
225
+ h: date.toLocaleString(locale, { hour: "numeric", hour12: true }),
226
+ hh: date.toLocaleString(locale, { hour: "2-digit", hour12: true }),
227
+ H: date.toLocaleString(locale, { hour: "numeric", hour12: false }),
228
+ HH: date.toLocaleString(locale, { hour: "2-digit", hour12: false }),
229
+ // Day period
230
+ aa: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLowerCase(),
231
+ AA: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toUpperCase(),
232
+ // Day of week
233
+ E: date.toLocaleString(locale, { weekday: "short" }),
234
+ EE: date.toLocaleString(locale, { weekday: "short" }),
235
+ EEE: date.toLocaleString(locale, { weekday: "short" }),
236
+ EEEE: date.toLocaleString(locale, { weekday: "long" }),
237
+ // Date of month
238
+ d: datetime.day,
239
+ dd: date.toLocaleString(locale, { day: "2-digit" }),
240
+ // Months
241
+ M: datetime.month + 1,
242
+ MM: date.toLocaleString(locale, { month: "2-digit" }),
243
+ MMM: date.toLocaleString(locale, { month: "short" }),
244
+ MMMM: date.toLocaleString(locale, { month: "long" }),
245
+ // Years
246
+ yy: date.toLocaleString(locale, { year: "2-digit" }),
247
+ yyyy: date.toLocaleString(locale, { year: "numeric" }),
248
+ YY: date.toLocaleString(locale, { year: "2-digit" }),
249
+ YYYY: date.toLocaleString(locale, { year: "numeric" })
250
+ };
251
+ let result = formatString;
252
+ for (const key in formats) {
253
+ result = result.replace(createRegEx(key), "$1" + formats[key] + "$3");
254
+ }
255
+ return result;
256
+ }
257
+
258
+ // src/format-range.ts
259
+ function formatRange(startDate, endDate, formatter, toString, timeZone) {
260
+ let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
261
+ let separatorIndex = -1;
262
+ for (let i = 0; i < parts.length; i++) {
263
+ let part = parts[i];
264
+ if (part.source === "shared" && part.type === "literal") {
265
+ separatorIndex = i;
266
+ } else if (part.source === "endRange") {
267
+ break;
268
+ }
269
+ }
270
+ let start = "";
271
+ let end = "";
272
+ for (let i = 0; i < parts.length; i++) {
273
+ if (i < separatorIndex) {
274
+ start += parts[i].value;
275
+ } else if (i > separatorIndex) {
276
+ end += parts[i].value;
277
+ }
278
+ }
279
+ return toString(start, end);
280
+ }
281
+
282
+ // src/format-selected-date.ts
283
+ var import_date5 = require("@internationalized/date");
284
+
285
+ // src/get-day-formatter.ts
286
+ var import_date4 = require("@internationalized/date");
287
+
288
+ // src/get-era-format.ts
289
+ function getEraFormat(date) {
290
+ return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
291
+ }
292
+
293
+ // src/get-day-formatter.ts
294
+ function getDayFormatter(locale, timeZone) {
295
+ const date = (0, import_date4.toCalendarDateTime)((0, import_date4.today)(timeZone));
296
+ return new import_date4.DateFormatter(locale, {
297
+ weekday: "long",
298
+ month: "long",
299
+ year: "numeric",
300
+ day: "numeric",
301
+ era: getEraFormat(date),
302
+ timeZone
303
+ });
304
+ }
305
+
306
+ // src/format-selected-date.ts
307
+ function formatSelectedDate(startDate, endDate, locale, timeZone) {
308
+ let start = startDate;
309
+ let end = endDate ?? startDate;
310
+ let formatter = getDayFormatter(locale, timeZone);
311
+ if ((0, import_date5.isSameDay)(start, end)) {
312
+ return formatter.format(start.toDate(timeZone));
313
+ }
314
+ return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
315
+ }
316
+
317
+ // src/format-visible-range.ts
318
+ var import_date7 = require("@internationalized/date");
319
+
320
+ // src/get-month-formatter.ts
321
+ var import_date6 = require("@internationalized/date");
322
+ function getMonthFormatter(locale, timeZone) {
323
+ const date = (0, import_date6.toCalendarDate)((0, import_date6.today)(timeZone));
324
+ return new import_date6.DateFormatter(locale, {
325
+ month: "long",
326
+ year: "numeric",
327
+ era: getEraFormat(date),
328
+ calendar: date?.calendar.identifier,
329
+ timeZone
330
+ });
331
+ }
332
+
333
+ // src/format-visible-range.ts
334
+ function formatVisibleRange(startDate, endDate, locale, timeZone) {
335
+ const start = startDate;
336
+ const end = endDate ?? startDate;
337
+ const dayFormatter = getDayFormatter(locale, timeZone);
338
+ if (!(0, import_date7.isSameDay)(start, (0, import_date7.startOfMonth)(start))) {
339
+ return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
340
+ }
341
+ const monthFormatter = getMonthFormatter(locale, timeZone);
342
+ if ((0, import_date7.isSameDay)(end, (0, import_date7.endOfMonth)(start))) {
343
+ return monthFormatter.format(start.toDate(timeZone));
344
+ }
345
+ if ((0, import_date7.isSameDay)(end, (0, import_date7.endOfMonth)(end))) {
346
+ return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
347
+ }
348
+ return "";
349
+ }
350
+
351
+ // src/get-decade-range.ts
352
+ function getDecadeRange(year) {
353
+ const computedYear = year - year % 10 - 1;
354
+ const years = [];
355
+ for (let i = 0; i < 12; i += 1) {
356
+ const value = computedYear + i;
357
+ years.push(value);
358
+ }
359
+ return years;
360
+ }
361
+
362
+ // src/get-month-days.ts
363
+ var import_date9 = require("@internationalized/date");
364
+
365
+ // src/get-start-of-week.ts
366
+ var import_date8 = require("@internationalized/date");
367
+ function getStartOfWeek(date, locale, firstDayOfWeek = 0) {
368
+ const day = (0, import_date8.getDayOfWeek)(date, locale);
369
+ const diff = (day - firstDayOfWeek + 7) % 7;
370
+ return date.subtract({ days: diff });
371
+ }
372
+
373
+ // src/get-month-days.ts
374
+ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
375
+ const weekDate = from.add({ weeks: weekIndex });
376
+ const dates = [];
377
+ let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
378
+ while (dates.length < 7) {
379
+ dates.push(date);
380
+ let nextDate = date.add({ days: 1 });
381
+ if ((0, import_date9.isSameDay)(date, nextDate)) {
382
+ break;
383
+ }
384
+ date = nextDate;
385
+ }
386
+ return dates;
387
+ }
388
+ function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
389
+ const monthWeeks = (0, import_date9.getWeeksInMonth)(from, locale);
390
+ const weeks = [...new Array(numOfWeeks ?? monthWeeks).keys()];
391
+ return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
392
+ }
393
+
394
+ // src/get-month-names.ts
395
+ function getMonthNames(locale, format = "long") {
396
+ const date = new Date(2021, 0, 1);
397
+ const monthNames = [];
398
+ for (let i = 0; i < 12; i++) {
399
+ monthNames.push(date.toLocaleString(locale, { month: format }));
400
+ date.setMonth(date.getMonth() + 1);
401
+ }
402
+ return monthNames;
403
+ }
404
+
405
+ // src/get-weekday-formats.ts
406
+ var import_date10 = require("@internationalized/date");
407
+ function getWeekdayFormats(locale, timeZone) {
408
+ const longFormat = new import_date10.DateFormatter(locale, { weekday: "long", timeZone });
409
+ const shortFormat = new import_date10.DateFormatter(locale, { weekday: "short", timeZone });
410
+ const narrowFormat = new import_date10.DateFormatter(locale, { weekday: "narrow", timeZone });
411
+ return (value) => {
412
+ const date = value instanceof Date ? value : value.toDate(timeZone);
413
+ return {
414
+ value,
415
+ short: shortFormat.format(date),
416
+ long: longFormat.format(date),
417
+ narrow: narrowFormat.format(date)
418
+ };
419
+ };
420
+ }
421
+
422
+ // src/get-week-days.ts
423
+ function getWeekDays(date, startOfWeekProp, timeZone, locale) {
424
+ const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
425
+ const weeks = [...new Array(7).keys()];
426
+ const format = getWeekdayFormats(locale, timeZone);
427
+ return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
428
+ }
429
+
430
+ // src/get-year-range.ts
431
+ function getYearsRange(range) {
432
+ const years = [];
433
+ for (let year = range.from; year <= range.to; year += 1) {
434
+ years.push(year);
435
+ }
436
+ return years;
437
+ }
438
+
439
+ // src/mutation.ts
440
+ var import_date11 = require("@internationalized/date");
441
+ function getTodayDate(timeZone) {
442
+ return (0, import_date11.today)(timeZone ?? (0, import_date11.getLocalTimeZone)());
443
+ }
444
+ function getNextDay(date) {
445
+ return date.add({ days: 1 });
446
+ }
447
+ function getPreviousDay(date) {
448
+ return date.subtract({ days: 1 });
449
+ }
450
+ function setMonth(date, month) {
451
+ return date.set({ month });
452
+ }
453
+ function setYear(date, year) {
454
+ return date.set({ year });
455
+ }
456
+ function setCalendar(date, calendar) {
457
+ return (0, import_date11.toCalendar)((0, import_date11.toCalendarDateTime)(date), calendar);
458
+ }
459
+ function setDate(date, startDate, isDateUnavailable2, locale, minValue, maxValue) {
460
+ let result;
461
+ result = constrainValue(date, minValue, maxValue);
462
+ result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable2);
463
+ return result;
464
+ }
465
+ function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable2) {
466
+ if (!isDateUnavailable2) {
467
+ return date;
468
+ }
469
+ while (date.compare(minValue) >= 0 && isDateUnavailable2(date, locale)) {
470
+ date = date.subtract({ days: 1 });
471
+ }
472
+ if (date.compare(minValue) >= 0) {
473
+ return date;
474
+ }
475
+ }
476
+
477
+ // src/pagination.ts
478
+ var import_date12 = require("@internationalized/date");
479
+ function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
480
+ return function getDate(options) {
481
+ const { startDate, focusedDate } = options;
482
+ const endDate = getEndDate(startDate, visibleDuration);
483
+ if (isDateInvalid(focusedDate, minValue, maxValue)) {
484
+ return {
485
+ startDate,
486
+ focusedDate: constrainValue(focusedDate, minValue, maxValue),
487
+ endDate
488
+ };
489
+ }
490
+ if (focusedDate.compare(startDate) < 0) {
491
+ return {
492
+ startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
493
+ endDate,
494
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
495
+ };
496
+ }
497
+ if (focusedDate.compare(endDate) > 0) {
498
+ return {
499
+ startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
500
+ endDate,
501
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
502
+ };
503
+ }
504
+ return {
505
+ startDate,
506
+ endDate,
507
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
508
+ };
509
+ };
510
+ }
511
+ function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
512
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
513
+ const start = startDate.add(visibleDuration);
514
+ return adjust({
515
+ focusedDate: focusedDate.add(visibleDuration),
516
+ startDate: alignStart(
517
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
518
+ visibleDuration,
519
+ locale
520
+ )
521
+ });
522
+ }
523
+ function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
524
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
525
+ let start = startDate.subtract(visibleDuration);
526
+ return adjust({
527
+ focusedDate: focusedDate.subtract(visibleDuration),
528
+ startDate: alignStart(
529
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
530
+ visibleDuration,
531
+ locale
532
+ )
533
+ });
534
+ }
535
+ function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
536
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
537
+ if (visibleDuration.days) {
538
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
539
+ }
540
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
541
+ return adjust({
542
+ focusedDate: focusedDate.add({ weeks: 1 }),
543
+ startDate
544
+ });
545
+ }
546
+ }
547
+ function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
548
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
549
+ if (visibleDuration.days) {
550
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
551
+ }
552
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
553
+ return adjust({
554
+ focusedDate: focusedDate.subtract({ weeks: 1 }),
555
+ startDate
556
+ });
557
+ }
558
+ }
559
+ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
560
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
561
+ if (visibleDuration.days) {
562
+ return adjust({
563
+ focusedDate: startDate,
564
+ startDate
565
+ });
566
+ }
567
+ if (visibleDuration.weeks) {
568
+ return adjust({
569
+ focusedDate: (0, import_date12.startOfWeek)(focusedDate, locale),
570
+ startDate
571
+ });
572
+ }
573
+ if (visibleDuration.months || visibleDuration.years) {
574
+ return adjust({
575
+ focusedDate: (0, import_date12.startOfMonth)(focusedDate),
576
+ startDate
577
+ });
578
+ }
579
+ }
580
+ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
581
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
582
+ const endDate = getEndDate(startDate, visibleDuration);
583
+ if (visibleDuration.days) {
584
+ return adjust({
585
+ focusedDate: endDate,
586
+ startDate
587
+ });
588
+ }
589
+ if (visibleDuration.weeks) {
590
+ return adjust({
591
+ //@ts-expect-error - endOfWeek is loosely typed
592
+ focusedDate: (0, import_date12.endOfWeek)(focusedDate, locale),
593
+ startDate
594
+ });
595
+ }
596
+ if (visibleDuration.months || visibleDuration.years) {
597
+ return adjust({
598
+ focusedDate: (0, import_date12.endOfMonth)(focusedDate),
599
+ startDate
600
+ });
601
+ }
602
+ }
603
+ function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
604
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
605
+ if (!larger && !visibleDuration.days) {
606
+ return adjust({
607
+ focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
608
+ startDate
609
+ });
610
+ }
611
+ if (visibleDuration.days) {
612
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
613
+ }
614
+ if (visibleDuration.weeks) {
615
+ return adjust({
616
+ focusedDate: focusedDate.add({ months: 1 }),
617
+ startDate
618
+ });
619
+ }
620
+ if (visibleDuration.months || visibleDuration.years) {
621
+ return adjust({
622
+ focusedDate: focusedDate.add({ years: 1 }),
623
+ startDate
624
+ });
625
+ }
626
+ }
627
+ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
628
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
629
+ if (!larger && !visibleDuration.days) {
630
+ return adjust({
631
+ focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
632
+ startDate
633
+ });
634
+ }
635
+ if (visibleDuration.days) {
636
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
637
+ }
638
+ if (visibleDuration.weeks) {
639
+ return adjust({
640
+ focusedDate: focusedDate.subtract({ months: 1 }),
641
+ startDate
642
+ });
643
+ }
644
+ if (visibleDuration.months || visibleDuration.years) {
645
+ return adjust({
646
+ focusedDate: focusedDate.subtract({ years: 1 }),
647
+ startDate
648
+ });
649
+ }
650
+ }
651
+
652
+ // src/parse-date.ts
653
+ var import_date13 = require("@internationalized/date");
654
+ function parseDateString(date, locale, timeZone) {
655
+ const regex = createRegex(locale, timeZone);
656
+ const { year, month, day } = extract(regex, date) ?? {};
657
+ if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
658
+ return new import_date13.CalendarDateTime(+year, +month, +day);
659
+ }
660
+ const time = Date.parse(date);
661
+ if (!isNaN(time)) {
662
+ const date2 = new Date(time);
663
+ return new import_date13.CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
664
+ }
665
+ }
666
+ function createRegex(locale, timeZone) {
667
+ const formatter = new import_date13.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
668
+ const parts = formatter.formatToParts(new Date(2e3, 11, 25));
669
+ return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
670
+ }
671
+ function extract(pattern, str) {
672
+ const matches = str.match(pattern);
673
+ return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
674
+ const groupMatches = group.match(/<(.+)>/);
675
+ if (!groupMatches || groupMatches.length <= 0) {
676
+ return null;
677
+ }
678
+ return group.match(/<(.+)>/)?.[1];
679
+ }).reduce(
680
+ (acc, curr, index) => {
681
+ if (!curr)
682
+ return acc;
683
+ if (matches && matches.length > index) {
684
+ acc[curr] = matches[index + 1];
685
+ } else {
686
+ acc[curr] = null;
687
+ }
688
+ return acc;
689
+ },
690
+ {}
691
+ );
692
+ }
693
+ // Annotate the CommonJS export names for ESM import in node:
694
+ 0 && (module.exports = {
695
+ alignCenter,
696
+ alignDate,
697
+ alignEnd,
698
+ alignStart,
699
+ alignStartDate,
700
+ constrainStart,
701
+ constrainValue,
702
+ formatDate,
703
+ formatRange,
704
+ formatSelectedDate,
705
+ formatVisibleRange,
706
+ getAdjustedDateFn,
707
+ getDayFormatter,
708
+ getDaysInWeek,
709
+ getDecadeRange,
710
+ getEndDate,
711
+ getMonthDays,
712
+ getMonthFormatter,
713
+ getMonthNames,
714
+ getNextDay,
715
+ getNextPage,
716
+ getNextRow,
717
+ getNextSection,
718
+ getPreviousAvailableDate,
719
+ getPreviousDay,
720
+ getPreviousPage,
721
+ getPreviousRow,
722
+ getPreviousSection,
723
+ getSectionEnd,
724
+ getSectionStart,
725
+ getTodayDate,
726
+ getUnitDuration,
727
+ getWeekDays,
728
+ getWeekdayFormats,
729
+ getYearsRange,
730
+ isDateDisabled,
731
+ isDateEqual,
732
+ isDateInvalid,
733
+ isDateOutsideVisibleRange,
734
+ isDateUnavailable,
735
+ isNextVisibleRangeInvalid,
736
+ isPreviousVisibleRangeInvalid,
737
+ isTodayDate,
738
+ parseDateString,
739
+ setCalendar,
740
+ setDate,
741
+ setMonth,
742
+ setYear
743
+ });
744
+ //# sourceMappingURL=index.js.map