@zag-js/date-utils 0.0.0-dev-20230107115230 → 0.0.0-dev-20230107162034

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.mjs CHANGED
@@ -1,34 +1,30 @@
1
1
  import {
2
2
  addSegment,
3
3
  setSegment
4
- } from "./chunk-EXWX3KZT.mjs";
5
- import {
6
- SEGMENT_PAGE_STEP,
7
- isSegmentEditable
8
- } from "./chunk-6NI2PIAA.mjs";
4
+ } from "./chunk-CAV5WKCZ.mjs";
9
5
  import {
10
6
  getSegmentLimits
11
- } from "./chunk-2DZ3KIVJ.mjs";
7
+ } from "./chunk-L3YHK2WH.mjs";
12
8
  import {
13
9
  getMonthDates
14
- } from "./chunk-ECAENYV6.mjs";
10
+ } from "./chunk-HUBKWHIN.mjs";
15
11
  import {
16
12
  getDatesInWeek,
17
13
  getWeekDates
18
- } from "./chunk-M4F23P2U.mjs";
14
+ } from "./chunk-JZVHAOWX.mjs";
19
15
  import {
20
16
  getYearsRange
21
17
  } from "./chunk-TTJVXKJY.mjs";
22
18
  import {
23
- clampDate,
24
19
  getNextDay,
20
+ getPreviousAvailableDate,
25
21
  getPreviousDay,
26
22
  getTodayDate,
27
23
  setCalendar,
28
24
  setDate,
29
25
  setMonth,
30
26
  setYear
31
- } from "./chunk-C4U2N3JC.mjs";
27
+ } from "./chunk-ZZPZ2BFS.mjs";
32
28
  import {
33
29
  getNextPage,
34
30
  getNextRow,
@@ -38,11 +34,15 @@ import {
38
34
  getPreviousSection,
39
35
  getSectionEnd,
40
36
  getSectionStart
41
- } from "./chunk-VWVBJ5CB.mjs";
37
+ } from "./chunk-MY373KF2.mjs";
38
+ import {
39
+ SEGMENT_PAGE_STEP,
40
+ isSegmentEditable
41
+ } from "./chunk-6NI2PIAA.mjs";
42
42
  import {
43
43
  alignDate,
44
44
  alignStartDate
45
- } from "./chunk-6XKXGQP6.mjs";
45
+ } from "./chunk-BUT5IUNZ.mjs";
46
46
  import {
47
47
  isDateDisabled,
48
48
  isDateEqual,
@@ -52,26 +52,28 @@ import {
52
52
  isNextVisibleRangeInvalid,
53
53
  isPreviousVisibleRangeInvalid,
54
54
  isTodayDate
55
- } from "./chunk-7JERMWT3.mjs";
55
+ } from "./chunk-6EJZROXM.mjs";
56
56
  import {
57
57
  alignCenter,
58
58
  alignEnd,
59
59
  alignStart,
60
60
  constrainStart,
61
61
  constrainValue
62
- } from "./chunk-HP2COJGP.mjs";
62
+ } from "./chunk-MGPXEJO4.mjs";
63
63
  import {
64
64
  getEndDate,
65
65
  getUnitDuration
66
66
  } from "./chunk-ZSLC7OI2.mjs";
67
67
  import {
68
68
  formatSelectedDate
69
- } from "./chunk-DI2YG6VG.mjs";
70
- import "./chunk-TCPXGBJP.mjs";
69
+ } from "./chunk-GKU5M6QU.mjs";
70
+ import {
71
+ formatVisibleRange
72
+ } from "./chunk-URPTPFL3.mjs";
71
73
  import {
72
74
  formatRange
73
- } from "./chunk-XHAL6X5Z.mjs";
74
- import "./chunk-FJMTHABG.mjs";
75
+ } from "./chunk-HKHGJ6WS.mjs";
76
+ import "./chunk-BBE325GQ.mjs";
75
77
  export {
76
78
  SEGMENT_PAGE_STEP,
77
79
  addSegment,
@@ -80,11 +82,11 @@ export {
80
82
  alignEnd,
81
83
  alignStart,
82
84
  alignStartDate,
83
- clampDate,
84
85
  constrainStart,
85
86
  constrainValue,
86
87
  formatRange,
87
88
  formatSelectedDate,
89
+ formatVisibleRange,
88
90
  getDatesInWeek,
89
91
  getEndDate,
90
92
  getMonthDates,
@@ -92,6 +94,7 @@ export {
92
94
  getNextPage,
93
95
  getNextRow,
94
96
  getNextSection,
97
+ getPreviousAvailableDate,
95
98
  getPreviousDay,
96
99
  getPreviousPage,
97
100
  getPreviousRow,
@@ -1,13 +1,13 @@
1
- import { CalendarDate, Calendar } from '@internationalized/date';
2
- import { D as DateContext } from './types-9f60d2f1.js';
1
+ import { CalendarDate, Calendar, DateValue } from '@internationalized/date';
2
+ import { a as DateAvailableFn } from './types-cbf8b45a.js';
3
3
 
4
- declare function clampDate(ctx: DateContext, date: CalendarDate): CalendarDate;
5
4
  declare function getTodayDate(timezone: string): CalendarDate;
6
5
  declare function getNextDay(date: CalendarDate): CalendarDate;
7
6
  declare function getPreviousDay(date: CalendarDate): CalendarDate;
8
7
  declare function setMonth(date: CalendarDate, month: number): CalendarDate;
9
8
  declare function setYear(date: CalendarDate, year: number): CalendarDate;
10
9
  declare function setCalendar(date: CalendarDate, calendar: Calendar): CalendarDate;
11
- declare function setDate(ctx: DateContext, date: CalendarDate, nextDate: CalendarDate, startDate: CalendarDate): CalendarDate | undefined;
10
+ declare function setDate(date: CalendarDate, startDate: CalendarDate, isDateUnavailable: DateAvailableFn, minValue: CalendarDate, maxValue: CalendarDate): CalendarDate | undefined;
11
+ declare function getPreviousAvailableDate(date: CalendarDate, minValue: DateValue, isDateUnavailable?: DateAvailableFn): CalendarDate | undefined;
12
12
 
13
- export { clampDate, getNextDay, getPreviousDay, getTodayDate, setCalendar, setDate, setMonth, setYear };
13
+ export { getNextDay, getPreviousAvailableDate, getPreviousDay, getTodayDate, setCalendar, setDate, setMonth, setYear };
package/dist/mutation.js CHANGED
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/mutation.ts
21
21
  var mutation_exports = {};
22
22
  __export(mutation_exports, {
23
- clampDate: () => clampDate,
24
23
  getNextDay: () => getNextDay,
24
+ getPreviousAvailableDate: () => getPreviousAvailableDate,
25
25
  getPreviousDay: () => getPreviousDay,
26
26
  getTodayDate: () => getTodayDate,
27
27
  setCalendar: () => setCalendar,
@@ -30,43 +30,23 @@ __export(mutation_exports, {
30
30
  setYear: () => setYear
31
31
  });
32
32
  module.exports = __toCommonJS(mutation_exports);
33
- var import_date3 = require("@internationalized/date");
33
+ var import_date2 = require("@internationalized/date");
34
34
 
35
35
  // src/constrain.ts
36
36
  var import_date = require("@internationalized/date");
37
- function constrainValue(ctx, date) {
38
- let { min, max } = ctx;
39
- if (min) {
40
- date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(min));
37
+ function constrainValue(date, minValue, maxValue) {
38
+ if (minValue) {
39
+ date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(minValue));
41
40
  }
42
- if (max) {
43
- date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(max));
41
+ if (maxValue) {
42
+ date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(maxValue));
44
43
  }
45
44
  return date;
46
45
  }
47
46
 
48
- // src/assertion.ts
49
- var import_date2 = require("@internationalized/date");
50
- function isDateInvalid(ctx, date) {
51
- return ctx.min != null && date.compare(ctx.min) < 0 || ctx.max != null && date.compare(ctx.max) > 0;
52
- }
53
- function isDateUnavailable(ctx, date) {
54
- var _a;
55
- if (!date) {
56
- return false;
57
- }
58
- if ((_a = ctx.isUnavailable) == null ? void 0 : _a.call(ctx, date)) {
59
- return true;
60
- }
61
- return isDateInvalid(ctx, date);
62
- }
63
-
64
47
  // src/mutation.ts
65
- function clampDate(ctx, date) {
66
- return constrainValue(ctx, date);
67
- }
68
48
  function getTodayDate(timezone) {
69
- return (0, import_date3.today)(timezone);
49
+ return (0, import_date2.today)(timezone);
70
50
  }
71
51
  function getNextDay(date) {
72
52
  return date.add({ days: 1 });
@@ -81,26 +61,19 @@ function setYear(date, year) {
81
61
  return date.set({ year });
82
62
  }
83
63
  function setCalendar(date, calendar) {
84
- return (0, import_date3.toCalendar)((0, import_date3.toCalendarDate)(date), calendar);
64
+ return (0, import_date2.toCalendar)((0, import_date2.toCalendarDate)(date), calendar);
85
65
  }
86
- function setDate(ctx, date, nextDate, startDate) {
66
+ function setDate(date, startDate, isDateUnavailable, minValue, maxValue) {
87
67
  let result;
88
- result = clampDate(ctx, nextDate);
89
- result = getPreviousAvailableDate(ctx, nextDate, startDate);
90
- if (!result)
91
- return;
92
- result = (0, import_date3.toCalendar)(result, (date == null ? void 0 : date.calendar) || new import_date3.GregorianCalendar());
93
- if (date && "hour" in date) {
94
- return date.set(result);
95
- }
68
+ result = constrainValue(date, minValue, maxValue);
69
+ result = getPreviousAvailableDate(date, startDate, isDateUnavailable);
96
70
  return result;
97
71
  }
98
- function getPreviousAvailableDate(ctx, date, min) {
99
- const minValue = min != null ? min : ctx.min;
100
- if (!isDateUnavailable(ctx, date) || !minValue) {
72
+ function getPreviousAvailableDate(date, minValue, isDateUnavailable) {
73
+ if (!isDateUnavailable) {
101
74
  return date;
102
75
  }
103
- while (date.compare(minValue) >= 0 && isDateUnavailable(ctx, date)) {
76
+ while (date.compare(minValue) >= 0 && isDateUnavailable(date)) {
104
77
  date = date.subtract({ days: 1 });
105
78
  }
106
79
  if (date.compare(minValue) >= 0) {
@@ -109,8 +82,8 @@ function getPreviousAvailableDate(ctx, date, min) {
109
82
  }
110
83
  // Annotate the CommonJS export names for ESM import in node:
111
84
  0 && (module.exports = {
112
- clampDate,
113
85
  getNextDay,
86
+ getPreviousAvailableDate,
114
87
  getPreviousDay,
115
88
  getTodayDate,
116
89
  setCalendar,
package/dist/mutation.mjs CHANGED
@@ -1,18 +1,17 @@
1
1
  import {
2
- clampDate,
3
2
  getNextDay,
3
+ getPreviousAvailableDate,
4
4
  getPreviousDay,
5
5
  getTodayDate,
6
6
  setCalendar,
7
7
  setDate,
8
8
  setMonth,
9
9
  setYear
10
- } from "./chunk-C4U2N3JC.mjs";
11
- import "./chunk-7JERMWT3.mjs";
12
- import "./chunk-HP2COJGP.mjs";
10
+ } from "./chunk-ZZPZ2BFS.mjs";
11
+ import "./chunk-MGPXEJO4.mjs";
13
12
  export {
14
- clampDate,
15
13
  getNextDay,
14
+ getPreviousAvailableDate,
16
15
  getPreviousDay,
17
16
  getTodayDate,
18
17
  setCalendar,
@@ -1,25 +1,44 @@
1
- import { CalendarDate } from '@internationalized/date';
2
- import { D as DateContext } from './types-9f60d2f1.js';
1
+ import { CalendarDate, DateDuration } from '@internationalized/date';
3
2
 
4
- declare function getNextPage(ctx: DateContext, date: CalendarDate, startDate: CalendarDate): {
3
+ declare function getNextPage(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
5
4
  startDate: CalendarDate;
6
5
  focusedDate: CalendarDate;
6
+ endDate: CalendarDate;
7
7
  };
8
- declare function getPreviousPage(ctx: DateContext, date: CalendarDate, startDate: CalendarDate): {
8
+ declare function getPreviousPage(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
9
9
  startDate: CalendarDate;
10
10
  focusedDate: CalendarDate;
11
+ endDate: CalendarDate;
11
12
  };
12
- declare function getSectionStart(ctx: DateContext, date: CalendarDate, startDate: CalendarDate): CalendarDate | undefined;
13
- declare function getSectionEnd(ctx: DateContext, date: CalendarDate, endDate: CalendarDate): CalendarDate | undefined;
14
- declare function getNextSection(ctx: DateContext, date: CalendarDate, larger?: boolean): CalendarDate | undefined;
15
- declare function getPreviousSection(ctx: DateContext, date: CalendarDate, larger?: boolean): CalendarDate | undefined;
16
- declare function getNextRow(ctx: DateContext, date: CalendarDate, startDate: CalendarDate): CalendarDate | {
13
+ declare function getNextRow(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
17
14
  startDate: CalendarDate;
18
15
  focusedDate: CalendarDate;
16
+ endDate: CalendarDate;
19
17
  } | undefined;
20
- declare function getPreviousRow(ctx: DateContext, date: CalendarDate, startDate: CalendarDate): CalendarDate | {
18
+ declare function getPreviousRow(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
21
19
  startDate: CalendarDate;
22
20
  focusedDate: CalendarDate;
21
+ endDate: CalendarDate;
22
+ } | undefined;
23
+ declare function getSectionStart(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
24
+ startDate: CalendarDate;
25
+ focusedDate: CalendarDate;
26
+ endDate: CalendarDate;
27
+ } | undefined;
28
+ declare function getSectionEnd(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
29
+ startDate: CalendarDate;
30
+ focusedDate: CalendarDate;
31
+ endDate: CalendarDate;
32
+ } | undefined;
33
+ declare function getNextSection(focusedDate: CalendarDate, startDate: CalendarDate, larger: boolean, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
34
+ startDate: CalendarDate;
35
+ focusedDate: CalendarDate;
36
+ endDate: CalendarDate;
37
+ } | undefined;
38
+ declare function getPreviousSection(focusedDate: CalendarDate, startDate: CalendarDate, larger: boolean, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
39
+ startDate: CalendarDate;
40
+ focusedDate: CalendarDate;
41
+ endDate: CalendarDate;
23
42
  } | undefined;
24
43
 
25
44
  export { getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
@@ -30,24 +30,28 @@ __export(pagination_exports, {
30
30
  getSectionStart: () => getSectionStart
31
31
  });
32
32
  module.exports = __toCommonJS(pagination_exports);
33
- var import_date2 = require("@internationalized/date");
33
+ var import_date3 = require("@internationalized/date");
34
34
 
35
- // src/constrain.ts
35
+ // src/assertion.ts
36
36
  var import_date = require("@internationalized/date");
37
- function alignStart(ctx, date) {
38
- let { locale, duration } = ctx;
37
+ function isDateInvalid(date, minValue, maxValue) {
38
+ return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
39
+ }
40
+
41
+ // src/constrain.ts
42
+ var import_date2 = require("@internationalized/date");
43
+ function alignStart(date, duration, locale, min, max) {
39
44
  let aligned = date;
40
45
  if (duration.years) {
41
- aligned = (0, import_date.startOfYear)(date);
46
+ aligned = (0, import_date2.startOfYear)(date);
42
47
  } else if (duration.months) {
43
- aligned = (0, import_date.startOfMonth)(date);
48
+ aligned = (0, import_date2.startOfMonth)(date);
44
49
  } else if (duration.weeks) {
45
- aligned = (0, import_date.startOfWeek)(date, locale);
50
+ aligned = (0, import_date2.startOfWeek)(date, locale);
46
51
  }
47
- return constrainStart(ctx, date, aligned);
52
+ return constrainStart(date, aligned, duration, locale, min, max);
48
53
  }
49
- function alignEnd(ctx, date) {
50
- const { duration } = ctx;
54
+ function alignEnd(date, duration, locale, min, max) {
51
55
  let d = { ...duration };
52
56
  if (d.days) {
53
57
  d.days--;
@@ -58,29 +62,27 @@ function alignEnd(ctx, date) {
58
62
  } else if (d.years) {
59
63
  d.years--;
60
64
  }
61
- let aligned = alignStart(ctx, date).subtract(d);
62
- return constrainStart(ctx, date, aligned);
63
- }
64
- function constrainValue(ctx, date) {
65
- let { min, max } = ctx;
66
- if (min) {
67
- date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(min));
68
- }
69
- if (max) {
70
- date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(max));
71
- }
72
- return date;
65
+ let aligned = alignStart(date, duration, locale).subtract(d);
66
+ return constrainStart(date, aligned, duration, locale, min, max);
73
67
  }
74
- function constrainStart(ctx, date, aligned) {
75
- let { min, max } = ctx;
68
+ function constrainStart(date, aligned, duration, locale, min, max) {
76
69
  if (min && date.compare(min) >= 0) {
77
- aligned = (0, import_date.maxDate)(aligned, alignStart(ctx, (0, import_date.toCalendarDate)(min)));
70
+ aligned = (0, import_date2.maxDate)(aligned, alignStart((0, import_date2.toCalendarDate)(min), duration, locale));
78
71
  }
79
72
  if (max && date.compare(max) <= 0) {
80
- aligned = (0, import_date.minDate)(aligned, alignEnd(ctx, (0, import_date.toCalendarDate)(max)));
73
+ aligned = (0, import_date2.minDate)(aligned, alignEnd((0, import_date2.toCalendarDate)(max), duration, locale));
81
74
  }
82
75
  return aligned;
83
76
  }
77
+ function constrainValue(date, minValue, maxValue) {
78
+ if (minValue) {
79
+ date = (0, import_date2.maxDate)(date, (0, import_date2.toCalendarDate)(minValue));
80
+ }
81
+ if (maxValue) {
82
+ date = (0, import_date2.minDate)(date, (0, import_date2.toCalendarDate)(maxValue));
83
+ }
84
+ return date;
85
+ }
84
86
 
85
87
  // src/duration.ts
86
88
  function getUnitDuration(duration) {
@@ -90,94 +92,186 @@ function getUnitDuration(duration) {
90
92
  }
91
93
  return d;
92
94
  }
95
+ function getEndDate(startDate, duration) {
96
+ let d = { ...duration };
97
+ if (d.days) {
98
+ d.days--;
99
+ } else {
100
+ d.days = -1;
101
+ }
102
+ return startDate.add(d);
103
+ }
93
104
 
94
105
  // src/pagination.ts
95
- function getNextPage(ctx, date, startDate) {
96
- const start = startDate.add(ctx.duration);
97
- return {
98
- startDate: alignStart(ctx, constrainStart(ctx, date, start)),
99
- focusedDate: constrainValue(ctx, date.add(ctx.duration))
106
+ function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
107
+ return function getDate(options) {
108
+ const { startDate, focusedDate } = options;
109
+ const endDate = getEndDate(startDate, visibleDuration);
110
+ if (isDateInvalid(focusedDate, minValue, maxValue)) {
111
+ return {
112
+ startDate,
113
+ focusedDate: constrainValue(focusedDate, minValue, maxValue),
114
+ endDate
115
+ };
116
+ }
117
+ if (focusedDate.compare(startDate) < 0) {
118
+ return {
119
+ startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
120
+ endDate,
121
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
122
+ };
123
+ }
124
+ if (focusedDate.compare(endDate) > 0) {
125
+ return {
126
+ startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
127
+ endDate,
128
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
129
+ };
130
+ }
131
+ return {
132
+ startDate,
133
+ endDate,
134
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
135
+ };
100
136
  };
101
137
  }
102
- function getPreviousPage(ctx, date, startDate) {
103
- const start = startDate.subtract(ctx.duration);
104
- return {
105
- startDate: alignStart(ctx, constrainStart(ctx, date, start)),
106
- focusedDate: constrainValue(ctx, date.subtract(ctx.duration))
107
- };
138
+ function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
139
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
140
+ const start = startDate.add(visibleDuration);
141
+ return adjust({
142
+ focusedDate: focusedDate.add(visibleDuration),
143
+ startDate: alignStart(
144
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
145
+ visibleDuration,
146
+ locale
147
+ )
148
+ });
108
149
  }
109
- function getSectionStart(ctx, date, startDate) {
110
- const d = ctx.duration;
111
- if (d.days) {
112
- return startDate;
150
+ function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
151
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
152
+ let start = startDate.subtract(visibleDuration);
153
+ return adjust({
154
+ focusedDate: focusedDate.subtract(visibleDuration),
155
+ startDate: alignStart(
156
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
157
+ visibleDuration,
158
+ locale
159
+ )
160
+ });
161
+ }
162
+ function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
163
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
164
+ if (visibleDuration.days) {
165
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
113
166
  }
114
- if (d.weeks) {
115
- return (0, import_date2.startOfWeek)(date, ctx.locale);
167
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
168
+ return adjust({
169
+ focusedDate: focusedDate.add({ weeks: 1 }),
170
+ startDate
171
+ });
172
+ }
173
+ }
174
+ function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
175
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
176
+ if (visibleDuration.days) {
177
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
116
178
  }
117
- if (d.months || d.years) {
118
- return (0, import_date2.startOfMonth)(date);
179
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
180
+ return adjust({
181
+ focusedDate: focusedDate.subtract({ weeks: 1 }),
182
+ startDate
183
+ });
119
184
  }
120
185
  }
121
- function getSectionEnd(ctx, date, endDate) {
122
- const d = ctx.duration;
123
- if (d.days) {
124
- return endDate;
186
+ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
187
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
188
+ if (visibleDuration.days) {
189
+ return adjust({
190
+ focusedDate: startDate,
191
+ startDate
192
+ });
125
193
  }
126
- if (d.weeks) {
127
- return (0, import_date2.endOfWeek)(date, ctx.locale);
194
+ if (visibleDuration.weeks) {
195
+ return adjust({
196
+ focusedDate: (0, import_date3.startOfWeek)(focusedDate, locale),
197
+ startDate
198
+ });
128
199
  }
129
- if (d.months || d.years) {
130
- return (0, import_date2.endOfMonth)(date);
200
+ if (visibleDuration.months || visibleDuration.years) {
201
+ return adjust({
202
+ focusedDate: (0, import_date3.startOfMonth)(focusedDate),
203
+ startDate
204
+ });
131
205
  }
132
206
  }
133
- function getNextSection(ctx, date, larger) {
134
- const d = ctx.duration;
135
- const unitDuration = getUnitDuration(ctx.duration);
136
- if (!larger && !d.days) {
137
- return date.add(unitDuration);
138
- }
139
- if (d.days) {
140
- return date.add(d);
207
+ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
208
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
209
+ const endDate = getEndDate(startDate, visibleDuration);
210
+ if (visibleDuration.days) {
211
+ return adjust({
212
+ focusedDate: endDate,
213
+ startDate
214
+ });
141
215
  }
142
- if (d.weeks) {
143
- return date.add({ months: 1 });
216
+ if (visibleDuration.weeks) {
217
+ return adjust({
218
+ focusedDate: (0, import_date3.endOfWeek)(focusedDate, locale),
219
+ startDate
220
+ });
144
221
  }
145
- if (d.months || d.years) {
146
- return date.add({ years: 1 });
222
+ if (visibleDuration.months || visibleDuration.years) {
223
+ return adjust({
224
+ focusedDate: (0, import_date3.endOfMonth)(focusedDate),
225
+ startDate
226
+ });
147
227
  }
148
228
  }
149
- function getPreviousSection(ctx, date, larger) {
150
- const d = ctx.duration;
151
- const unitDuration = getUnitDuration(ctx.duration);
152
- if (!larger && !d.days) {
153
- return date.subtract(unitDuration);
229
+ function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
230
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
231
+ if (!larger && !visibleDuration.days) {
232
+ return adjust({
233
+ focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
234
+ startDate
235
+ });
154
236
  }
155
- if (d.days) {
156
- return date.subtract(ctx.duration);
237
+ if (visibleDuration.days) {
238
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
157
239
  }
158
- if (d.weeks) {
159
- return date.subtract({ months: 1 });
240
+ if (visibleDuration.weeks) {
241
+ return adjust({
242
+ focusedDate: focusedDate.add({ months: 1 }),
243
+ startDate
244
+ });
160
245
  }
161
- if (d.months || d.years) {
162
- return date.subtract({ years: 1 });
246
+ if (visibleDuration.months || visibleDuration.years) {
247
+ return adjust({
248
+ focusedDate: focusedDate.add({ years: 1 }),
249
+ startDate
250
+ });
163
251
  }
164
252
  }
165
- function getNextRow(ctx, date, startDate) {
166
- const d = ctx.duration;
167
- if (d.days) {
168
- return getNextPage(ctx, date, startDate);
253
+ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
254
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
255
+ if (!larger && !visibleDuration.days) {
256
+ return adjust({
257
+ focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
258
+ startDate
259
+ });
169
260
  }
170
- if (d.weeks || d.months || d.years) {
171
- return date.add({ weeks: 1 });
261
+ if (visibleDuration.days) {
262
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
172
263
  }
173
- }
174
- function getPreviousRow(ctx, date, startDate) {
175
- const d = ctx.duration;
176
- if (d.days) {
177
- return getPreviousPage(ctx, date, startDate);
264
+ if (visibleDuration.weeks) {
265
+ return adjust({
266
+ focusedDate: focusedDate.subtract({ months: 1 }),
267
+ startDate
268
+ });
178
269
  }
179
- if (d.weeks || d.months || d.years) {
180
- return date.subtract({ weeks: 1 });
270
+ if (visibleDuration.months || visibleDuration.years) {
271
+ return adjust({
272
+ focusedDate: focusedDate.subtract({ years: 1 }),
273
+ startDate
274
+ });
181
275
  }
182
276
  }
183
277
  // Annotate the CommonJS export names for ESM import in node:
@@ -7,8 +7,9 @@ import {
7
7
  getPreviousSection,
8
8
  getSectionEnd,
9
9
  getSectionStart
10
- } from "./chunk-VWVBJ5CB.mjs";
11
- import "./chunk-HP2COJGP.mjs";
10
+ } from "./chunk-MY373KF2.mjs";
11
+ import "./chunk-6EJZROXM.mjs";
12
+ import "./chunk-MGPXEJO4.mjs";
12
13
  import "./chunk-ZSLC7OI2.mjs";
13
14
  export {
14
15
  getNextPage,
@@ -1,5 +1,5 @@
1
1
  import * as _internationalized_date from '@internationalized/date';
2
- import { c as DateGranularity } from './types-9f60d2f1.js';
2
+ import { b as DateGranularity } from './types-cbf8b45a.js';
3
3
 
4
4
  declare function getTodayPlaceholderDate(timeZone: string): _internationalized_date.ZonedDateTime;
5
5
  declare function createPlaceholderDate(granularity: DateGranularity, timeZone: string): _internationalized_date.CalendarDate | _internationalized_date.ZonedDateTime;