@zag-js/date-utils 0.10.2 → 0.10.4

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 (104) hide show
  1. package/dist/align.d.ts +4 -7
  2. package/dist/align.js +11 -83
  3. package/dist/align.mjs +24 -9
  4. package/dist/assertion.d.ts +10 -13
  5. package/dist/assertion.js +19 -48
  6. package/dist/assertion.mjs +36 -20
  7. package/dist/constrain.d.ts +6 -9
  8. package/dist/constrain.js +26 -52
  9. package/dist/constrain.mjs +58 -14
  10. package/dist/duration.d.ts +3 -7
  11. package/dist/duration.js +6 -30
  12. package/dist/duration.mjs +18 -8
  13. package/dist/format-date.d.ts +2 -5
  14. package/dist/format-date.js +32 -54
  15. package/dist/format-date.mjs +53 -6
  16. package/dist/format-range.d.ts +2 -5
  17. package/dist/format-range.js +5 -28
  18. package/dist/format-range.mjs +24 -6
  19. package/dist/format-selected-date.d.ts +2 -5
  20. package/dist/format-selected-date.js +10 -77
  21. package/dist/format-selected-date.mjs +15 -9
  22. package/dist/format-visible-range.d.ts +2 -5
  23. package/dist/format-visible-range.js +12 -68
  24. package/dist/format-visible-range.mjs +22 -9
  25. package/dist/get-day-formatter.d.ts +2 -5
  26. package/dist/get-day-formatter.js +9 -37
  27. package/dist/get-day-formatter.mjs +16 -7
  28. package/dist/get-decade-range.d.ts +1 -3
  29. package/dist/get-decade-range.js +5 -28
  30. package/dist/get-decade-range.mjs +11 -6
  31. package/dist/get-end-of-week.d.ts +2 -6
  32. package/dist/get-era-format.d.ts +2 -5
  33. package/dist/get-era-format.js +5 -28
  34. package/dist/get-era-format.mjs +5 -6
  35. package/dist/get-month-days.d.ts +3 -6
  36. package/dist/get-month-days.js +13 -45
  37. package/dist/get-month-days.mjs +24 -9
  38. package/dist/get-month-formatter.d.ts +2 -5
  39. package/dist/get-month-formatter.js +10 -38
  40. package/dist/get-month-formatter.mjs +15 -7
  41. package/dist/get-month-names.d.ts +1 -3
  42. package/dist/get-month-names.js +5 -28
  43. package/dist/get-month-names.mjs +11 -6
  44. package/dist/get-start-of-week.d.ts +2 -6
  45. package/dist/get-start-of-week.js +10 -32
  46. package/dist/get-start-of-week.mjs +9 -6
  47. package/dist/get-week-days.d.ts +3 -7
  48. package/dist/get-week-days.js +8 -55
  49. package/dist/get-week-days.mjs +11 -8
  50. package/dist/get-weekday-formats.d.ts +2 -5
  51. package/dist/get-weekday-formats.js +10 -32
  52. package/dist/get-weekday-formats.mjs +18 -6
  53. package/dist/get-year-range.d.ts +2 -4
  54. package/dist/get-year-range.js +5 -28
  55. package/dist/get-year-range.mjs +9 -6
  56. package/dist/index.d.ts +20 -21
  57. package/dist/index.js +74 -740
  58. package/dist/index.mjs +19 -138
  59. package/dist/mutation.d.ts +10 -14
  60. package/dist/mutation.js +17 -59
  61. package/dist/mutation.mjs +40 -21
  62. package/dist/pagination.d.ts +19 -23
  63. package/dist/pagination.js +35 -134
  64. package/dist/pagination.mjs +179 -25
  65. package/dist/parse-date.d.ts +2 -5
  66. package/dist/parse-date.js +13 -35
  67. package/dist/parse-date.mjs +40 -6
  68. package/dist/types.d.ts +8 -11
  69. package/package.json +3 -8
  70. package/src/assertion.ts +1 -1
  71. package/src/constrain.ts +2 -2
  72. package/src/format-date.ts +1 -1
  73. package/src/format-selected-date.ts +1 -1
  74. package/src/format-visible-range.ts +1 -1
  75. package/src/get-month-days.ts +1 -1
  76. package/src/get-start-of-week.ts +1 -1
  77. package/src/get-weekday-formats.ts +1 -1
  78. package/src/mutation.ts +8 -1
  79. package/src/pagination.ts +8 -1
  80. package/dist/chunk-5HGHDJ3L.mjs +0 -14
  81. package/dist/chunk-6FNTXW54.mjs +0 -52
  82. package/dist/chunk-6LXTZHZP.mjs +0 -22
  83. package/dist/chunk-AMZ7CJ5F.mjs +0 -18
  84. package/dist/chunk-BUT5IUNZ.mjs +0 -32
  85. package/dist/chunk-FJKH6IJZ.mjs +0 -21
  86. package/dist/chunk-G4VVKINZ.mjs +0 -14
  87. package/dist/chunk-HKHGJ6WS.mjs +0 -27
  88. package/dist/chunk-HLAN6TUA.mjs +0 -45
  89. package/dist/chunk-KBGJA6NB.mjs +0 -55
  90. package/dist/chunk-KLHRN7WS.mjs +0 -20
  91. package/dist/chunk-KN3YMOSL.mjs +0 -8
  92. package/dist/chunk-KQVWH4YA.mjs +0 -29
  93. package/dist/chunk-LGEGBP3O.mjs +0 -20
  94. package/dist/chunk-MGPXEJO4.mjs +0 -71
  95. package/dist/chunk-NV7UFBMY.mjs +0 -30
  96. package/dist/chunk-POBWDZPE.mjs +0 -200
  97. package/dist/chunk-SI75FOJ2.mjs +0 -11
  98. package/dist/chunk-TTJVXKJY.mjs +0 -12
  99. package/dist/chunk-WQYMLJUJ.mjs +0 -42
  100. package/dist/chunk-ZSLC7OI2.mjs +0 -22
  101. package/dist/get-end-of-week.js +0 -42
  102. package/dist/get-end-of-week.mjs +0 -11
  103. package/dist/types.js +0 -18
  104. package/dist/types.mjs +0 -0
@@ -1,138 +1,41 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/pagination.ts
21
- var pagination_exports = {};
22
- __export(pagination_exports, {
23
- getAdjustedDateFn: () => getAdjustedDateFn,
24
- getNextPage: () => getNextPage,
25
- getNextRow: () => getNextRow,
26
- getNextSection: () => getNextSection,
27
- getPreviousPage: () => getPreviousPage,
28
- getPreviousRow: () => getPreviousRow,
29
- getPreviousSection: () => getPreviousSection,
30
- getSectionEnd: () => getSectionEnd,
31
- getSectionStart: () => getSectionStart
32
- });
33
- module.exports = __toCommonJS(pagination_exports);
34
- var import_date3 = require("@internationalized/date");
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
35
4
 
36
- // src/assertion.ts
37
- var import_date = require("@internationalized/date");
38
- function isDateInvalid(date, minValue, maxValue) {
39
- return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
40
- }
5
+ const date = require('@internationalized/date');
6
+ const assertion = require('./assertion.js');
7
+ const constrain = require('./constrain.js');
8
+ const duration = require('./duration.js');
41
9
 
42
- // src/constrain.ts
43
- var import_date2 = require("@internationalized/date");
44
- function alignStart(date, duration, locale, min, max) {
45
- let aligned = date;
46
- if (duration.years) {
47
- aligned = (0, import_date2.startOfYear)(date);
48
- } else if (duration.months) {
49
- aligned = (0, import_date2.startOfMonth)(date);
50
- } else if (duration.weeks) {
51
- aligned = (0, import_date2.startOfWeek)(date, locale);
52
- }
53
- return constrainStart(date, aligned, duration, locale, min, max);
54
- }
55
- function alignEnd(date, duration, locale, min, max) {
56
- let d = { ...duration };
57
- if (d.days) {
58
- d.days--;
59
- } else if (d.weeks) {
60
- d.weeks--;
61
- } else if (d.months) {
62
- d.months--;
63
- } else if (d.years) {
64
- d.years--;
65
- }
66
- let aligned = alignStart(date, duration, locale).subtract(d);
67
- return constrainStart(date, aligned, duration, locale, min, max);
68
- }
69
- function constrainStart(date, aligned, duration, locale, min, max) {
70
- if (min && date.compare(min) >= 0) {
71
- aligned = (0, import_date2.maxDate)(aligned, alignStart((0, import_date2.toCalendarDate)(min), duration, locale));
72
- }
73
- if (max && date.compare(max) <= 0) {
74
- aligned = (0, import_date2.minDate)(aligned, alignEnd((0, import_date2.toCalendarDate)(max), duration, locale));
75
- }
76
- return aligned;
77
- }
78
- function constrainValue(date, minValue, maxValue) {
79
- if (minValue) {
80
- date = (0, import_date2.maxDate)(date, (0, import_date2.toCalendarDate)(minValue));
81
- }
82
- if (maxValue) {
83
- date = (0, import_date2.minDate)(date, (0, import_date2.toCalendarDate)(maxValue));
84
- }
85
- return date;
86
- }
87
-
88
- // src/duration.ts
89
- function getUnitDuration(duration) {
90
- let d = { ...duration };
91
- for (let key in d) {
92
- d[key] = 1;
93
- }
94
- return d;
95
- }
96
- function getEndDate(startDate, duration) {
97
- let d = { ...duration };
98
- if (d.days) {
99
- d.days--;
100
- } else {
101
- d.days = -1;
102
- }
103
- return startDate.add(d);
104
- }
105
-
106
- // src/pagination.ts
107
10
  function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
108
11
  return function getDate(options) {
109
12
  const { startDate, focusedDate } = options;
110
- const endDate = getEndDate(startDate, visibleDuration);
111
- if (isDateInvalid(focusedDate, minValue, maxValue)) {
13
+ const endDate = duration.getEndDate(startDate, visibleDuration);
14
+ if (assertion.isDateInvalid(focusedDate, minValue, maxValue)) {
112
15
  return {
113
16
  startDate,
114
- focusedDate: constrainValue(focusedDate, minValue, maxValue),
17
+ focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue),
115
18
  endDate
116
19
  };
117
20
  }
118
21
  if (focusedDate.compare(startDate) < 0) {
119
22
  return {
120
- startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
23
+ startDate: constrain.alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
121
24
  endDate,
122
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
25
+ focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue)
123
26
  };
124
27
  }
125
28
  if (focusedDate.compare(endDate) > 0) {
126
29
  return {
127
- startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
30
+ startDate: constrain.alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
128
31
  endDate,
129
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
32
+ focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue)
130
33
  };
131
34
  }
132
35
  return {
133
36
  startDate,
134
37
  endDate,
135
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
38
+ focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue)
136
39
  };
137
40
  };
138
41
  }
@@ -141,8 +44,8 @@ function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue,
141
44
  const start = startDate.add(visibleDuration);
142
45
  return adjust({
143
46
  focusedDate: focusedDate.add(visibleDuration),
144
- startDate: alignStart(
145
- constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
47
+ startDate: constrain.alignStart(
48
+ constrain.constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
146
49
  visibleDuration,
147
50
  locale
148
51
  )
@@ -153,8 +56,8 @@ function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minVal
153
56
  let start = startDate.subtract(visibleDuration);
154
57
  return adjust({
155
58
  focusedDate: focusedDate.subtract(visibleDuration),
156
- startDate: alignStart(
157
- constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
59
+ startDate: constrain.alignStart(
60
+ constrain.constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
158
61
  visibleDuration,
159
62
  locale
160
63
  )
@@ -194,20 +97,20 @@ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minVal
194
97
  }
195
98
  if (visibleDuration.weeks) {
196
99
  return adjust({
197
- focusedDate: (0, import_date3.startOfWeek)(focusedDate, locale),
100
+ focusedDate: date.startOfWeek(focusedDate, locale),
198
101
  startDate
199
102
  });
200
103
  }
201
104
  if (visibleDuration.months || visibleDuration.years) {
202
105
  return adjust({
203
- focusedDate: (0, import_date3.startOfMonth)(focusedDate),
106
+ focusedDate: date.startOfMonth(focusedDate),
204
107
  startDate
205
108
  });
206
109
  }
207
110
  }
208
111
  function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
209
112
  const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
210
- const endDate = getEndDate(startDate, visibleDuration);
113
+ const endDate = duration.getEndDate(startDate, visibleDuration);
211
114
  if (visibleDuration.days) {
212
115
  return adjust({
213
116
  focusedDate: endDate,
@@ -217,13 +120,13 @@ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue
217
120
  if (visibleDuration.weeks) {
218
121
  return adjust({
219
122
  //@ts-expect-error - endOfWeek is loosely typed
220
- focusedDate: (0, import_date3.endOfWeek)(focusedDate, locale),
123
+ focusedDate: date.endOfWeek(focusedDate, locale),
221
124
  startDate
222
125
  });
223
126
  }
224
127
  if (visibleDuration.months || visibleDuration.years) {
225
128
  return adjust({
226
- focusedDate: (0, import_date3.endOfMonth)(focusedDate),
129
+ focusedDate: date.endOfMonth(focusedDate),
227
130
  startDate
228
131
  });
229
132
  }
@@ -232,7 +135,7 @@ function getNextSection(focusedDate, startDate, larger, visibleDuration, locale,
232
135
  const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
233
136
  if (!larger && !visibleDuration.days) {
234
137
  return adjust({
235
- focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
138
+ focusedDate: focusedDate.add(duration.getUnitDuration(visibleDuration)),
236
139
  startDate
237
140
  });
238
141
  }
@@ -256,7 +159,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
256
159
  const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
257
160
  if (!larger && !visibleDuration.days) {
258
161
  return adjust({
259
- focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
162
+ focusedDate: focusedDate.subtract(duration.getUnitDuration(visibleDuration)),
260
163
  startDate
261
164
  });
262
165
  }
@@ -276,15 +179,13 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
276
179
  });
277
180
  }
278
181
  }
279
- // Annotate the CommonJS export names for ESM import in node:
280
- 0 && (module.exports = {
281
- getAdjustedDateFn,
282
- getNextPage,
283
- getNextRow,
284
- getNextSection,
285
- getPreviousPage,
286
- getPreviousRow,
287
- getPreviousSection,
288
- getSectionEnd,
289
- getSectionStart
290
- });
182
+
183
+ exports.getAdjustedDateFn = getAdjustedDateFn;
184
+ exports.getNextPage = getNextPage;
185
+ exports.getNextRow = getNextRow;
186
+ exports.getNextSection = getNextSection;
187
+ exports.getPreviousPage = getPreviousPage;
188
+ exports.getPreviousRow = getPreviousRow;
189
+ exports.getPreviousSection = getPreviousSection;
190
+ exports.getSectionEnd = getSectionEnd;
191
+ exports.getSectionStart = getSectionStart;
@@ -1,25 +1,179 @@
1
- import {
2
- getAdjustedDateFn,
3
- getNextPage,
4
- getNextRow,
5
- getNextSection,
6
- getPreviousPage,
7
- getPreviousRow,
8
- getPreviousSection,
9
- getSectionEnd,
10
- getSectionStart
11
- } from "./chunk-POBWDZPE.mjs";
12
- import "./chunk-HLAN6TUA.mjs";
13
- import "./chunk-MGPXEJO4.mjs";
14
- import "./chunk-ZSLC7OI2.mjs";
15
- export {
16
- getAdjustedDateFn,
17
- getNextPage,
18
- getNextRow,
19
- getNextSection,
20
- getPreviousPage,
21
- getPreviousRow,
22
- getPreviousSection,
23
- getSectionEnd,
24
- getSectionStart
25
- };
1
+ import { startOfWeek, startOfMonth, endOfWeek, endOfMonth } from '@internationalized/date';
2
+ import { isDateInvalid } from './assertion.mjs';
3
+ import { constrainValue, alignEnd, alignStart, constrainStart } from './constrain.mjs';
4
+ import { getEndDate, getUnitDuration } from './duration.mjs';
5
+
6
+ function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
7
+ return function getDate(options) {
8
+ const { startDate, focusedDate } = options;
9
+ const endDate = getEndDate(startDate, visibleDuration);
10
+ if (isDateInvalid(focusedDate, minValue, maxValue)) {
11
+ return {
12
+ startDate,
13
+ focusedDate: constrainValue(focusedDate, minValue, maxValue),
14
+ endDate
15
+ };
16
+ }
17
+ if (focusedDate.compare(startDate) < 0) {
18
+ return {
19
+ startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
20
+ endDate,
21
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
22
+ };
23
+ }
24
+ if (focusedDate.compare(endDate) > 0) {
25
+ return {
26
+ startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
27
+ endDate,
28
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
29
+ };
30
+ }
31
+ return {
32
+ startDate,
33
+ endDate,
34
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
35
+ };
36
+ };
37
+ }
38
+ function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
39
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
40
+ const start = startDate.add(visibleDuration);
41
+ return adjust({
42
+ focusedDate: focusedDate.add(visibleDuration),
43
+ startDate: alignStart(
44
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
45
+ visibleDuration,
46
+ locale
47
+ )
48
+ });
49
+ }
50
+ function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
51
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
52
+ let start = startDate.subtract(visibleDuration);
53
+ return adjust({
54
+ focusedDate: focusedDate.subtract(visibleDuration),
55
+ startDate: alignStart(
56
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
57
+ visibleDuration,
58
+ locale
59
+ )
60
+ });
61
+ }
62
+ function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
63
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
64
+ if (visibleDuration.days) {
65
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
66
+ }
67
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
68
+ return adjust({
69
+ focusedDate: focusedDate.add({ weeks: 1 }),
70
+ startDate
71
+ });
72
+ }
73
+ }
74
+ function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
75
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
76
+ if (visibleDuration.days) {
77
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
78
+ }
79
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
80
+ return adjust({
81
+ focusedDate: focusedDate.subtract({ weeks: 1 }),
82
+ startDate
83
+ });
84
+ }
85
+ }
86
+ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
87
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
88
+ if (visibleDuration.days) {
89
+ return adjust({
90
+ focusedDate: startDate,
91
+ startDate
92
+ });
93
+ }
94
+ if (visibleDuration.weeks) {
95
+ return adjust({
96
+ focusedDate: startOfWeek(focusedDate, locale),
97
+ startDate
98
+ });
99
+ }
100
+ if (visibleDuration.months || visibleDuration.years) {
101
+ return adjust({
102
+ focusedDate: startOfMonth(focusedDate),
103
+ startDate
104
+ });
105
+ }
106
+ }
107
+ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
108
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
109
+ const endDate = getEndDate(startDate, visibleDuration);
110
+ if (visibleDuration.days) {
111
+ return adjust({
112
+ focusedDate: endDate,
113
+ startDate
114
+ });
115
+ }
116
+ if (visibleDuration.weeks) {
117
+ return adjust({
118
+ //@ts-expect-error - endOfWeek is loosely typed
119
+ focusedDate: endOfWeek(focusedDate, locale),
120
+ startDate
121
+ });
122
+ }
123
+ if (visibleDuration.months || visibleDuration.years) {
124
+ return adjust({
125
+ focusedDate: endOfMonth(focusedDate),
126
+ startDate
127
+ });
128
+ }
129
+ }
130
+ function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
131
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
132
+ if (!larger && !visibleDuration.days) {
133
+ return adjust({
134
+ focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
135
+ startDate
136
+ });
137
+ }
138
+ if (visibleDuration.days) {
139
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
140
+ }
141
+ if (visibleDuration.weeks) {
142
+ return adjust({
143
+ focusedDate: focusedDate.add({ months: 1 }),
144
+ startDate
145
+ });
146
+ }
147
+ if (visibleDuration.months || visibleDuration.years) {
148
+ return adjust({
149
+ focusedDate: focusedDate.add({ years: 1 }),
150
+ startDate
151
+ });
152
+ }
153
+ }
154
+ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
155
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
156
+ if (!larger && !visibleDuration.days) {
157
+ return adjust({
158
+ focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
159
+ startDate
160
+ });
161
+ }
162
+ if (visibleDuration.days) {
163
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
164
+ }
165
+ if (visibleDuration.weeks) {
166
+ return adjust({
167
+ focusedDate: focusedDate.subtract({ months: 1 }),
168
+ startDate
169
+ });
170
+ }
171
+ if (visibleDuration.months || visibleDuration.years) {
172
+ return adjust({
173
+ focusedDate: focusedDate.subtract({ years: 1 }),
174
+ startDate
175
+ });
176
+ }
177
+ }
178
+
179
+ export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
@@ -1,5 +1,2 @@
1
- import { CalendarDateTime } from '@internationalized/date';
2
-
3
- declare function parseDateString(date: string, locale: string, timeZone: string): CalendarDateTime | undefined;
4
-
5
- export { parseDateString };
1
+ import { CalendarDateTime } from "@internationalized/date";
2
+ export declare function parseDateString(date: string, locale: string, timeZone: string): CalendarDateTime | undefined;
@@ -1,43 +1,23 @@
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);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
19
4
 
20
- // src/parse-date.ts
21
- var parse_date_exports = {};
22
- __export(parse_date_exports, {
23
- parseDateString: () => parseDateString
24
- });
25
- module.exports = __toCommonJS(parse_date_exports);
26
- var import_date = require("@internationalized/date");
27
- function parseDateString(date, locale, timeZone) {
5
+ const date = require('@internationalized/date');
6
+
7
+ function parseDateString(date$1, locale, timeZone) {
28
8
  const regex = createRegex(locale, timeZone);
29
- const { year, month, day } = extract(regex, date) ?? {};
9
+ const { year, month, day } = extract(regex, date$1) ?? {};
30
10
  if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
31
- return new import_date.CalendarDateTime(+year, +month, +day);
11
+ return new date.CalendarDateTime(+year, +month, +day);
32
12
  }
33
- const time = Date.parse(date);
13
+ const time = Date.parse(date$1);
34
14
  if (!isNaN(time)) {
35
15
  const date2 = new Date(time);
36
- return new import_date.CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
16
+ return new date.CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
37
17
  }
38
18
  }
39
19
  function createRegex(locale, timeZone) {
40
- const formatter = new import_date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
20
+ const formatter = new date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
41
21
  const parts = formatter.formatToParts(new Date(2e3, 11, 25));
42
22
  return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
43
23
  }
@@ -60,7 +40,5 @@ function extract(pattern, str) {
60
40
  return acc;
61
41
  }, {});
62
42
  }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- parseDateString
66
- });
43
+
44
+ exports.parseDateString = parseDateString;
@@ -1,6 +1,40 @@
1
- import {
2
- parseDateString
3
- } from "./chunk-WQYMLJUJ.mjs";
4
- export {
5
- parseDateString
6
- };
1
+ import { CalendarDateTime, DateFormatter } from '@internationalized/date';
2
+
3
+ function parseDateString(date, locale, timeZone) {
4
+ const regex = createRegex(locale, timeZone);
5
+ const { year, month, day } = extract(regex, date) ?? {};
6
+ if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
7
+ return new CalendarDateTime(+year, +month, +day);
8
+ }
9
+ const time = Date.parse(date);
10
+ if (!isNaN(time)) {
11
+ const date2 = new Date(time);
12
+ return new CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
13
+ }
14
+ }
15
+ function createRegex(locale, timeZone) {
16
+ const formatter = new DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
17
+ const parts = formatter.formatToParts(new Date(2e3, 11, 25));
18
+ return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
19
+ }
20
+ function extract(pattern, str) {
21
+ const matches = str.match(pattern);
22
+ return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
23
+ const groupMatches = group.match(/<(.+)>/);
24
+ if (!groupMatches || groupMatches.length <= 0) {
25
+ return null;
26
+ }
27
+ return group.match(/<(.+)>/)?.[1];
28
+ }).reduce((acc, curr, index) => {
29
+ if (!curr)
30
+ return acc;
31
+ if (matches && matches.length > index) {
32
+ acc[curr] = matches[index + 1];
33
+ } else {
34
+ acc[curr] = null;
35
+ }
36
+ return acc;
37
+ }, {});
38
+ }
39
+
40
+ export { parseDateString };
package/dist/types.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- import { DateFormatter, DateValue } from '@internationalized/date';
2
-
3
- type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
4
- type DateAlignment = "start" | "end" | "center";
5
- type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
6
- type DateAvailableFn = (date: DateValue, locale: string) => boolean;
7
- type GetPlaceholderFn = (options: {
1
+ import type { DateFormatter, DateValue } from "@internationalized/date";
2
+ export type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
3
+ export type DateAlignment = "start" | "end" | "center";
4
+ export type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
5
+ export type DateAvailableFn = (date: DateValue, locale: string) => boolean;
6
+ export type GetPlaceholderFn = (options: {
8
7
  field: string;
9
8
  locale: string;
10
9
  }) => string;
11
- type DateAdjustFn = (options: {
10
+ export type DateAdjustFn = (options: {
12
11
  startDate: DateValue;
13
12
  focusedDate: DateValue;
14
13
  }) => {
@@ -16,6 +15,4 @@ type DateAdjustFn = (options: {
16
15
  focusedDate: DateValue;
17
16
  endDate: DateValue;
18
17
  };
19
- type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
20
-
21
- export { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity, GetFormatterFn, GetPlaceholderFn };
18
+ export type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/date-utils",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "description": "Date utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "clean-package": "2.2.0",
32
- "@internationalized/date": "^3.2.0"
32
+ "@internationalized/date": "^3.3.0"
33
33
  },
34
34
  "module": "dist/index.mjs",
35
35
  "types": "dist/index.d.ts",
@@ -42,13 +42,8 @@
42
42
  "./package.json": "./package.json"
43
43
  },
44
44
  "scripts": {
45
- "build-fast": "tsup src",
46
- "start": "pnpm build --watch",
47
- "build": "tsup src --dts",
48
- "test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
45
+ "build": "vite build -c ../../../vite.config.ts",
49
46
  "lint": "eslint src --ext .ts,.tsx",
50
- "test-ci": "pnpm test --ci --runInBand",
51
- "test-watch": "pnpm test --watch -u",
52
47
  "typecheck": "tsc --noEmit"
53
48
  }
54
49
  }
package/src/assertion.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DateValue, isSameDay, isToday } from "@internationalized/date"
1
+ import { type DateValue, isSameDay, isToday } from "@internationalized/date"
2
2
  import type { DateAvailableFn } from "./types"
3
3
 
4
4
  export function isTodayDate(date: DateValue, timeZone: string) {
package/src/constrain.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
- DateDuration,
3
- DateValue,
2
+ type DateDuration,
3
+ type DateValue,
4
4
  maxDate,
5
5
  minDate,
6
6
  startOfMonth,
@@ -1,4 +1,4 @@
1
- import { DateValue, toCalendarDateTime } from "@internationalized/date"
1
+ import { type DateValue, toCalendarDateTime } from "@internationalized/date"
2
2
 
3
3
  function createRegEx(sign: string) {
4
4
  let symbols = "\\s|\\.|-|/|\\\\|,|\\$|\\!|\\?|:|;"
@@ -1,4 +1,4 @@
1
- import { DateValue, isSameDay } from "@internationalized/date"
1
+ import { type DateValue, isSameDay } from "@internationalized/date"
2
2
  import { formatRange } from "./format-range"
3
3
  import { getDayFormatter } from "./get-day-formatter"
4
4