@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.
Files changed (72) hide show
  1. package/dist/align.d.ts +4 -4
  2. package/dist/align.js +20 -24
  3. package/dist/align.mjs +2 -2
  4. package/dist/assertion.d.ts +8 -8
  5. package/dist/assertion.js +15 -16
  6. package/dist/assertion.mjs +1 -1
  7. package/dist/chunk-6EJZROXM.mjs +45 -0
  8. package/dist/{chunk-TCPXGBJP.mjs → chunk-BBE325GQ.mjs} +9 -8
  9. package/dist/chunk-BUT5IUNZ.mjs +32 -0
  10. package/dist/{chunk-EXWX3KZT.mjs → chunk-CAV5WKCZ.mjs} +4 -2
  11. package/dist/chunk-GKU5M6QU.mjs +25 -0
  12. package/dist/{chunk-XHAL6X5Z.mjs → chunk-HKHGJ6WS.mjs} +3 -3
  13. package/dist/{chunk-ECAENYV6.mjs → chunk-HUBKWHIN.mjs} +1 -1
  14. package/dist/{chunk-M4F23P2U.mjs → chunk-JZVHAOWX.mjs} +3 -3
  15. package/dist/{chunk-2DZ3KIVJ.mjs → chunk-L3YHK2WH.mjs} +1 -1
  16. package/dist/chunk-MGPXEJO4.mjs +71 -0
  17. package/dist/chunk-MY373KF2.mjs +198 -0
  18. package/dist/chunk-URPTPFL3.mjs +31 -0
  19. package/dist/chunk-ZZPZ2BFS.mjs +52 -0
  20. package/dist/constrain.d.ts +6 -7
  21. package/dist/constrain.js +20 -25
  22. package/dist/constrain.mjs +1 -1
  23. package/dist/format-range.d.ts +2 -3
  24. package/dist/format-range.js +3 -3
  25. package/dist/format-range.mjs +1 -1
  26. package/dist/format-selected-date.d.ts +3 -3
  27. package/dist/format-selected-date.js +13 -13
  28. package/dist/format-selected-date.mjs +3 -4
  29. package/dist/format-visible-range.d.ts +3 -3
  30. package/dist/format-visible-range.js +18 -17
  31. package/dist/format-visible-range.mjs +4 -26
  32. package/dist/get-formatter.d.ts +4 -3
  33. package/dist/get-formatter.js +6 -8
  34. package/dist/get-formatter.mjs +1 -2
  35. package/dist/get-month-dates.mjs +2 -2
  36. package/dist/get-week-dates.d.ts +1 -1
  37. package/dist/get-week-dates.js +2 -2
  38. package/dist/get-week-dates.mjs +1 -1
  39. package/dist/index.d.ts +3 -2
  40. package/dist/index.js +284 -181
  41. package/dist/index.mjs +22 -19
  42. package/dist/mutation.d.ts +5 -5
  43. package/dist/mutation.js +16 -43
  44. package/dist/mutation.mjs +4 -5
  45. package/dist/pagination.d.ts +29 -10
  46. package/dist/pagination.js +183 -89
  47. package/dist/pagination.mjs +3 -2
  48. package/dist/placeholder.d.ts +1 -1
  49. package/dist/segment-constants.d.ts +1 -1
  50. package/dist/segment-limit.d.ts +2 -2
  51. package/dist/segment-limit.js +1 -1
  52. package/dist/segment-limit.mjs +1 -1
  53. package/dist/segment-mutation.d.ts +3 -4
  54. package/dist/segment-mutation.js +4 -2
  55. package/dist/segment-mutation.mjs +1 -1
  56. package/dist/segment-parts.d.ts +2 -2
  57. package/dist/segment-parts.js +4 -4
  58. package/dist/segment-parts.mjs +6 -6
  59. package/dist/types-cbf8b45a.d.ts +35 -0
  60. package/dist/types.d.ts +1 -1
  61. package/package.json +1 -1
  62. package/dist/chunk-6XKXGQP6.mjs +0 -32
  63. package/dist/chunk-7JERMWT3.mjs +0 -46
  64. package/dist/chunk-C4U2N3JC.mjs +0 -65
  65. package/dist/chunk-DI2YG6VG.mjs +0 -24
  66. package/dist/chunk-FJMTHABG.mjs +0 -8
  67. package/dist/chunk-HP2COJGP.mjs +0 -76
  68. package/dist/chunk-VWVBJ5CB.mjs +0 -110
  69. package/dist/get-era-format.d.ts +0 -5
  70. package/dist/get-era-format.js +0 -32
  71. package/dist/get-era-format.mjs +0 -6
  72. 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(ctx, date) {
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(ctx, date).subtract(halfDuration);
82
- return constrainStart(ctx, date, aligned);
81
+ let aligned = alignStart(date, duration, locale).subtract(halfDuration);
82
+ return constrainStart(date, aligned, duration, locale, min, max);
83
83
  }
84
- function alignStart(ctx, date) {
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(ctx, date, aligned);
93
+ return constrainStart(date, aligned, duration, locale, min, max);
95
94
  }
96
- function alignEnd(ctx, date) {
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(ctx, date).subtract(d);
109
- return constrainStart(ctx, date, aligned);
106
+ let aligned = alignStart(date, duration, locale).subtract(d);
107
+ return constrainStart(date, aligned, duration, locale, min, max);
110
108
  }
111
- function constrainValue(ctx, date) {
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(ctx, (0, import_date.toCalendarDate)(min)));
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(ctx, (0, import_date.toCalendarDate)(max)));
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(ctx, date, alignment) {
129
+ function alignDate(date, alignment, duration, locale, min, max) {
134
130
  switch (alignment) {
135
131
  case "start":
136
- return alignStart(ctx, date);
132
+ return alignStart(date, duration, locale, min, max);
137
133
  case "end":
138
- return alignEnd(ctx, date);
134
+ return alignEnd(date, duration, locale, min, max);
139
135
  case "center":
140
136
  default:
141
- return alignCenter(ctx, date);
137
+ return alignCenter(date, duration, locale, min, max);
142
138
  }
143
139
  }
144
- function alignStartDate(ctx, focusedDate, startDate, endDate) {
145
- if (focusedDate.compare(startDate) < 0) {
146
- return alignEnd(ctx, focusedDate);
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 (focusedDate.compare(endDate) > 0) {
149
- return alignStart(ctx, focusedDate);
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, timezone) {
157
- return (0, import_date2.isToday)(date, timezone);
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(ctx, date) {
163
- return ctx.min != null && date.compare(ctx.min) < 0 || ctx.max != null && date.compare(ctx.max) > 0;
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(ctx, date, startDate, endDate) {
166
- return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(ctx, date);
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(ctx, date) {
169
- var _a;
164
+ function isDateUnavailable(date, isUnavailable, minValue, maxValue) {
170
165
  if (!date) {
171
166
  return false;
172
167
  }
173
- if ((_a = ctx.isUnavailable) == null ? void 0 : _a.call(ctx, date)) {
168
+ if (isUnavailable == null ? void 0 : isUnavailable(date)) {
174
169
  return true;
175
170
  }
176
- return isDateInvalid(ctx, date);
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(ctx, startDate) {
182
- let prev = startDate.subtract({ days: 1 });
183
- return (0, import_date2.isSameDay)(prev, startDate) || isDateInvalid(ctx, prev);
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(ctx, endDate) {
186
- let next = endDate.add({ days: 1 });
187
- return (0, import_date2.isSameDay)(next, endDate) || isDateInvalid(ctx, next);
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(ctx, formatter) {
210
- let parts = formatter.formatRangeToParts(ctx.start.toDate(ctx.timeZone), ctx.end.toDate(ctx.timeZone));
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 ctx.toString(start, end);
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-era-format.ts
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
- // src/get-formatter.ts
241
- function getDateFormatter(ctx) {
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(ctx) {
256
- const { start, end = start, timeZone } = ctx;
257
- let formatter = getDateFormatter(ctx);
258
- if (ctx.isSelectingRange || start == null || end == null) {
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(ctx, formatter);
271
+ return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
265
272
  }
266
273
 
267
- // src/get-week-dates.ts
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, import_date4.startOfWeek)(date, locale);
273
- let dayOfWeek = (0, import_date4.getDayOfWeek)(date, locale);
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, import_date4.isSameDay)(date, nextDate)) {
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, import_date4.startOfWeek)((0, import_date4.today)(timeZone), locale);
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 import_date5 = require("@internationalized/date");
326
+ var import_date6 = require("@internationalized/date");
300
327
  function getMonthDates(startDate, duration, locale) {
301
328
  var _a;
302
- let weeksInMonth = (0, import_date5.getWeeksInMonth)(startDate, locale);
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 import_date6 = require("@internationalized/date");
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, import_date6.today)(timezone);
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, import_date6.toCalendar)((0, import_date6.toCalendarDate)(date), calendar);
364
+ return (0, import_date7.toCalendar)((0, import_date7.toCalendarDate)(date), calendar);
341
365
  }
342
- function setDate(ctx, date, nextDate, startDate) {
366
+ function setDate(date, startDate, isDateUnavailable2, minValue, maxValue) {
343
367
  let result;
344
- result = clampDate(ctx, nextDate);
345
- result = getPreviousAvailableDate(ctx, nextDate, startDate);
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(ctx, date, min) {
355
- const minValue = min != null ? min : ctx.min;
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 && isDateUnavailable(ctx, date)) {
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 import_date7 = require("@internationalized/date");
369
- function getNextPage(ctx, date, startDate) {
370
- const start = startDate.add(ctx.duration);
371
- return {
372
- startDate: alignStart(ctx, constrainStart(ctx, date, start)),
373
- focusedDate: constrainValue(ctx, date.add(ctx.duration))
374
- };
375
- }
376
- function getPreviousPage(ctx, date, startDate) {
377
- const start = startDate.subtract(ctx.duration);
378
- return {
379
- startDate: alignStart(ctx, constrainStart(ctx, date, start)),
380
- focusedDate: constrainValue(ctx, date.subtract(ctx.duration))
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 getSectionStart(ctx, date, startDate) {
384
- const d = ctx.duration;
385
- if (d.days) {
386
- return startDate;
387
- }
388
- if (d.weeks) {
389
- return (0, import_date7.startOfWeek)(date, ctx.locale);
390
- }
391
- if (d.months || d.years) {
392
- return (0, import_date7.startOfMonth)(date);
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 getNextRow(ctx, date, startDate) {
440
- const d = ctx.duration;
441
- if (d.days) {
442
- return getNextPage(ctx, date, startDate);
443
- }
444
- if (d.weeks || d.months || d.years) {
445
- return date.add({ weeks: 1 });
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 getPreviousRow(ctx, date, startDate) {
449
- const d = ctx.duration;
450
- if (d.days) {
451
- return getPreviousPage(ctx, date, startDate);
452
- }
453
- if (d.weeks || d.months || d.years) {
454
- return date.subtract({ weeks: 1 });
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 import_date8 = require("@internationalized/date");
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, import_date8.getMinimumMonthInYear)(date),
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, import_date8.getMinimumDayInMonth)(date),
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,