@zag-js/date-utils 0.0.0-dev-20230107115230
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.
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/align.d.ts +7 -0
- package/dist/align.js +105 -0
- package/dist/align.mjs +9 -0
- package/dist/assertion.d.ts +13 -0
- package/dist/assertion.js +77 -0
- package/dist/assertion.mjs +20 -0
- package/dist/chunk-2DZ3KIVJ.mjs +73 -0
- package/dist/chunk-6NI2PIAA.mjs +27 -0
- package/dist/chunk-6XKXGQP6.mjs +32 -0
- package/dist/chunk-7JERMWT3.mjs +46 -0
- package/dist/chunk-C4U2N3JC.mjs +65 -0
- package/dist/chunk-DI2YG6VG.mjs +24 -0
- package/dist/chunk-ECAENYV6.mjs +19 -0
- package/dist/chunk-EXWX3KZT.mjs +64 -0
- package/dist/chunk-FJMTHABG.mjs +8 -0
- package/dist/chunk-HP2COJGP.mjs +76 -0
- package/dist/chunk-M4F23P2U.mjs +35 -0
- package/dist/chunk-TCPXGBJP.mjs +33 -0
- package/dist/chunk-TTJVXKJY.mjs +12 -0
- package/dist/chunk-VWVBJ5CB.mjs +110 -0
- package/dist/chunk-XHAL6X5Z.mjs +27 -0
- package/dist/chunk-ZSLC7OI2.mjs +22 -0
- package/dist/constrain.d.ts +10 -0
- package/dist/constrain.js +97 -0
- package/dist/constrain.mjs +14 -0
- package/dist/duration.d.ts +11 -0
- package/dist/duration.js +47 -0
- package/dist/duration.mjs +8 -0
- package/dist/format-range.d.ts +6 -0
- package/dist/format-range.js +51 -0
- package/dist/format-range.mjs +6 -0
- package/dist/format-selected-date.d.ts +6 -0
- package/dist/format-selected-date.js +86 -0
- package/dist/format-selected-date.mjs +9 -0
- package/dist/format-visible-range.d.ts +6 -0
- package/dist/format-visible-range.js +102 -0
- package/dist/format-visible-range.mjs +30 -0
- package/dist/get-era-format.d.ts +5 -0
- package/dist/get-era-format.js +32 -0
- package/dist/get-era-format.mjs +6 -0
- package/dist/get-formatter.d.ts +7 -0
- package/dist/get-formatter.js +61 -0
- package/dist/get-formatter.mjs +9 -0
- package/dist/get-month-dates.d.ts +5 -0
- package/dist/get-month-dates.js +65 -0
- package/dist/get-month-dates.mjs +7 -0
- package/dist/get-week-dates.d.ts +7 -0
- package/dist/get-week-dates.js +60 -0
- package/dist/get-week-dates.mjs +8 -0
- package/dist/get-year-range.d.ts +7 -0
- package/dist/get-year-range.js +36 -0
- package/dist/get-year-range.mjs +6 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +656 -0
- package/dist/index.mjs +120 -0
- package/dist/mutation.d.ts +13 -0
- package/dist/mutation.js +120 -0
- package/dist/mutation.mjs +22 -0
- package/dist/pagination.d.ts +25 -0
- package/dist/pagination.js +193 -0
- package/dist/pagination.mjs +22 -0
- package/dist/placeholder.d.ts +7 -0
- package/dist/placeholder.js +47 -0
- package/dist/placeholder.mjs +21 -0
- package/dist/segment-constants.d.ts +2 -0
- package/dist/segment-constants.js +52 -0
- package/dist/segment-constants.mjs +8 -0
- package/dist/segment-limit.d.ts +14 -0
- package/dist/segment-limit.js +97 -0
- package/dist/segment-limit.mjs +6 -0
- package/dist/segment-mutation.d.ts +8 -0
- package/dist/segment-mutation.js +89 -0
- package/dist/segment-mutation.mjs +8 -0
- package/dist/segment-parts.d.ts +25 -0
- package/dist/segment-parts.js +143 -0
- package/dist/segment-parts.mjs +37 -0
- package/dist/types-9f60d2f1.d.ts +61 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +53 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
SEGMENT_PAGE_STEP: () => SEGMENT_PAGE_STEP,
|
|
24
|
+
addSegment: () => addSegment,
|
|
25
|
+
alignCenter: () => alignCenter,
|
|
26
|
+
alignDate: () => alignDate,
|
|
27
|
+
alignEnd: () => alignEnd,
|
|
28
|
+
alignStart: () => alignStart,
|
|
29
|
+
alignStartDate: () => alignStartDate,
|
|
30
|
+
clampDate: () => clampDate,
|
|
31
|
+
constrainStart: () => constrainStart,
|
|
32
|
+
constrainValue: () => constrainValue,
|
|
33
|
+
formatRange: () => formatRange,
|
|
34
|
+
formatSelectedDate: () => formatSelectedDate,
|
|
35
|
+
getDatesInWeek: () => getDatesInWeek,
|
|
36
|
+
getEndDate: () => getEndDate,
|
|
37
|
+
getMonthDates: () => getMonthDates,
|
|
38
|
+
getNextDay: () => getNextDay,
|
|
39
|
+
getNextPage: () => getNextPage,
|
|
40
|
+
getNextRow: () => getNextRow,
|
|
41
|
+
getNextSection: () => getNextSection,
|
|
42
|
+
getPreviousDay: () => getPreviousDay,
|
|
43
|
+
getPreviousPage: () => getPreviousPage,
|
|
44
|
+
getPreviousRow: () => getPreviousRow,
|
|
45
|
+
getPreviousSection: () => getPreviousSection,
|
|
46
|
+
getSectionEnd: () => getSectionEnd,
|
|
47
|
+
getSectionStart: () => getSectionStart,
|
|
48
|
+
getSegmentLimits: () => getSegmentLimits,
|
|
49
|
+
getTodayDate: () => getTodayDate,
|
|
50
|
+
getUnitDuration: () => getUnitDuration,
|
|
51
|
+
getWeekDates: () => getWeekDates,
|
|
52
|
+
getYearsRange: () => getYearsRange,
|
|
53
|
+
isDateDisabled: () => isDateDisabled,
|
|
54
|
+
isDateEqual: () => isDateEqual,
|
|
55
|
+
isDateInvalid: () => isDateInvalid,
|
|
56
|
+
isDateOutsideVisibleRange: () => isDateOutsideVisibleRange,
|
|
57
|
+
isDateUnavailable: () => isDateUnavailable,
|
|
58
|
+
isNextVisibleRangeInvalid: () => isNextVisibleRangeInvalid,
|
|
59
|
+
isPreviousVisibleRangeInvalid: () => isPreviousVisibleRangeInvalid,
|
|
60
|
+
isSegmentEditable: () => isSegmentEditable,
|
|
61
|
+
isTodayDate: () => isTodayDate,
|
|
62
|
+
setCalendar: () => setCalendar,
|
|
63
|
+
setDate: () => setDate,
|
|
64
|
+
setMonth: () => setMonth,
|
|
65
|
+
setSegment: () => setSegment,
|
|
66
|
+
setYear: () => setYear
|
|
67
|
+
});
|
|
68
|
+
module.exports = __toCommonJS(src_exports);
|
|
69
|
+
|
|
70
|
+
// src/constrain.ts
|
|
71
|
+
var import_date = require("@internationalized/date");
|
|
72
|
+
function alignCenter(ctx, date) {
|
|
73
|
+
const { duration } = ctx;
|
|
74
|
+
let halfDuration = {};
|
|
75
|
+
for (let key in duration) {
|
|
76
|
+
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
77
|
+
if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
|
|
78
|
+
halfDuration[key]--;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
let aligned = alignStart(ctx, date).subtract(halfDuration);
|
|
82
|
+
return constrainStart(ctx, date, aligned);
|
|
83
|
+
}
|
|
84
|
+
function alignStart(ctx, date) {
|
|
85
|
+
let { locale, duration } = ctx;
|
|
86
|
+
let aligned = date;
|
|
87
|
+
if (duration.years) {
|
|
88
|
+
aligned = (0, import_date.startOfYear)(date);
|
|
89
|
+
} else if (duration.months) {
|
|
90
|
+
aligned = (0, import_date.startOfMonth)(date);
|
|
91
|
+
} else if (duration.weeks) {
|
|
92
|
+
aligned = (0, import_date.startOfWeek)(date, locale);
|
|
93
|
+
}
|
|
94
|
+
return constrainStart(ctx, date, aligned);
|
|
95
|
+
}
|
|
96
|
+
function alignEnd(ctx, date) {
|
|
97
|
+
const { duration } = ctx;
|
|
98
|
+
let d = { ...duration };
|
|
99
|
+
if (d.days) {
|
|
100
|
+
d.days--;
|
|
101
|
+
} else if (d.weeks) {
|
|
102
|
+
d.weeks--;
|
|
103
|
+
} else if (d.months) {
|
|
104
|
+
d.months--;
|
|
105
|
+
} else if (d.years) {
|
|
106
|
+
d.years--;
|
|
107
|
+
}
|
|
108
|
+
let aligned = alignStart(ctx, date).subtract(d);
|
|
109
|
+
return constrainStart(ctx, date, aligned);
|
|
110
|
+
}
|
|
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;
|
|
123
|
+
if (min && date.compare(min) >= 0) {
|
|
124
|
+
aligned = (0, import_date.maxDate)(aligned, alignStart(ctx, (0, import_date.toCalendarDate)(min)));
|
|
125
|
+
}
|
|
126
|
+
if (max && date.compare(max) <= 0) {
|
|
127
|
+
aligned = (0, import_date.minDate)(aligned, alignEnd(ctx, (0, import_date.toCalendarDate)(max)));
|
|
128
|
+
}
|
|
129
|
+
return aligned;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/align.ts
|
|
133
|
+
function alignDate(ctx, date, alignment) {
|
|
134
|
+
switch (alignment) {
|
|
135
|
+
case "start":
|
|
136
|
+
return alignStart(ctx, date);
|
|
137
|
+
case "end":
|
|
138
|
+
return alignEnd(ctx, date);
|
|
139
|
+
case "center":
|
|
140
|
+
default:
|
|
141
|
+
return alignCenter(ctx, date);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function alignStartDate(ctx, focusedDate, startDate, endDate) {
|
|
145
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
146
|
+
return alignEnd(ctx, focusedDate);
|
|
147
|
+
}
|
|
148
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
149
|
+
return alignStart(ctx, focusedDate);
|
|
150
|
+
}
|
|
151
|
+
return startDate;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/assertion.ts
|
|
155
|
+
var import_date2 = require("@internationalized/date");
|
|
156
|
+
function isTodayDate(date, timezone) {
|
|
157
|
+
return (0, import_date2.isToday)(date, timezone);
|
|
158
|
+
}
|
|
159
|
+
function isDateEqual(dateA, dateB) {
|
|
160
|
+
return dateB != null && (0, import_date2.isSameDay)(dateA, dateB);
|
|
161
|
+
}
|
|
162
|
+
function isDateInvalid(ctx, date) {
|
|
163
|
+
return ctx.min != null && date.compare(ctx.min) < 0 || ctx.max != null && date.compare(ctx.max) > 0;
|
|
164
|
+
}
|
|
165
|
+
function isDateDisabled(ctx, date, startDate, endDate) {
|
|
166
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(ctx, date);
|
|
167
|
+
}
|
|
168
|
+
function isDateUnavailable(ctx, date) {
|
|
169
|
+
var _a;
|
|
170
|
+
if (!date) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if ((_a = ctx.isUnavailable) == null ? void 0 : _a.call(ctx, date)) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
return isDateInvalid(ctx, date);
|
|
177
|
+
}
|
|
178
|
+
function isDateOutsideVisibleRange(date, startDate, endDate) {
|
|
179
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0;
|
|
180
|
+
}
|
|
181
|
+
function isPreviousVisibleRangeInvalid(ctx, startDate) {
|
|
182
|
+
let prev = startDate.subtract({ days: 1 });
|
|
183
|
+
return (0, import_date2.isSameDay)(prev, startDate) || isDateInvalid(ctx, prev);
|
|
184
|
+
}
|
|
185
|
+
function isNextVisibleRangeInvalid(ctx, endDate) {
|
|
186
|
+
let next = endDate.add({ days: 1 });
|
|
187
|
+
return (0, import_date2.isSameDay)(next, endDate) || isDateInvalid(ctx, next);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/duration.ts
|
|
191
|
+
function getUnitDuration(duration) {
|
|
192
|
+
let d = { ...duration };
|
|
193
|
+
for (let key in d) {
|
|
194
|
+
d[key] = 1;
|
|
195
|
+
}
|
|
196
|
+
return d;
|
|
197
|
+
}
|
|
198
|
+
function getEndDate(startDate, duration) {
|
|
199
|
+
let d = { ...duration };
|
|
200
|
+
if (d.days) {
|
|
201
|
+
d.days--;
|
|
202
|
+
} else {
|
|
203
|
+
d.days = -1;
|
|
204
|
+
}
|
|
205
|
+
return startDate.add(d);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/format-range.ts
|
|
209
|
+
function formatRange(ctx, formatter) {
|
|
210
|
+
let parts = formatter.formatRangeToParts(ctx.start.toDate(ctx.timeZone), ctx.end.toDate(ctx.timeZone));
|
|
211
|
+
let separatorIndex = -1;
|
|
212
|
+
for (let i = 0; i < parts.length; i++) {
|
|
213
|
+
let part = parts[i];
|
|
214
|
+
if (part.source === "shared" && part.type === "literal") {
|
|
215
|
+
separatorIndex = i;
|
|
216
|
+
} else if (part.source === "endRange") {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
let start = "";
|
|
221
|
+
let end = "";
|
|
222
|
+
for (let i = 0; i < parts.length; i++) {
|
|
223
|
+
if (i < separatorIndex) {
|
|
224
|
+
start += parts[i].value;
|
|
225
|
+
} else if (i > separatorIndex) {
|
|
226
|
+
end += parts[i].value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return ctx.toString(start, end);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/format-selected-date.ts
|
|
233
|
+
var import_date3 = require("@internationalized/date");
|
|
234
|
+
|
|
235
|
+
// src/get-era-format.ts
|
|
236
|
+
function getEraFormat(date) {
|
|
237
|
+
return (date == null ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/get-formatter.ts
|
|
241
|
+
function getDateFormatter(ctx) {
|
|
242
|
+
const { start, end = start, getDateFormatter: getDateFormatter2, timeZone } = ctx;
|
|
243
|
+
let era = getEraFormat(start) || getEraFormat(end);
|
|
244
|
+
return getDateFormatter2({
|
|
245
|
+
weekday: "long",
|
|
246
|
+
month: "long",
|
|
247
|
+
year: "numeric",
|
|
248
|
+
day: "numeric",
|
|
249
|
+
era,
|
|
250
|
+
timeZone
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 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) {
|
|
259
|
+
return "";
|
|
260
|
+
}
|
|
261
|
+
if ((0, import_date3.isSameDay)(start, end)) {
|
|
262
|
+
return formatter.format(start.toDate(timeZone));
|
|
263
|
+
}
|
|
264
|
+
return formatRange(ctx, formatter);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/get-week-dates.ts
|
|
268
|
+
var import_date4 = require("@internationalized/date");
|
|
269
|
+
function getDatesInWeek(weekIndex, fromDate, locale) {
|
|
270
|
+
let date = fromDate.add({ weeks: weekIndex });
|
|
271
|
+
let dates = [];
|
|
272
|
+
date = (0, import_date4.startOfWeek)(date, locale);
|
|
273
|
+
let dayOfWeek = (0, import_date4.getDayOfWeek)(date, locale);
|
|
274
|
+
for (let i = 0; i < dayOfWeek; i++) {
|
|
275
|
+
dates.push(null);
|
|
276
|
+
}
|
|
277
|
+
while (dates.length < 7) {
|
|
278
|
+
dates.push(date);
|
|
279
|
+
let nextDate = date.add({ days: 1 });
|
|
280
|
+
if ((0, import_date4.isSameDay)(date, nextDate)) {
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
date = nextDate;
|
|
284
|
+
}
|
|
285
|
+
while (dates.length < 7) {
|
|
286
|
+
dates.push(null);
|
|
287
|
+
}
|
|
288
|
+
return dates;
|
|
289
|
+
}
|
|
290
|
+
function getWeekDates(timeZone, locale) {
|
|
291
|
+
let weekStart = (0, import_date4.startOfWeek)((0, import_date4.today)(timeZone), locale);
|
|
292
|
+
let weekArr = [...new Array(7).keys()];
|
|
293
|
+
return weekArr.map((index) => {
|
|
294
|
+
return weekStart.add({ days: index }).toDate(timeZone);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/get-month-dates.ts
|
|
299
|
+
var import_date5 = require("@internationalized/date");
|
|
300
|
+
function getMonthDates(startDate, duration, locale) {
|
|
301
|
+
var _a;
|
|
302
|
+
let weeksInMonth = (0, import_date5.getWeeksInMonth)(startDate, locale);
|
|
303
|
+
let numOfWeeks = (_a = duration.weeks) != null ? _a : weeksInMonth;
|
|
304
|
+
let weekArr = [...new Array(numOfWeeks).keys()];
|
|
305
|
+
return weekArr.map((index) => {
|
|
306
|
+
return getDatesInWeek(index, startDate, locale);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/get-year-range.ts
|
|
311
|
+
function getYearsRange(range) {
|
|
312
|
+
const years = [];
|
|
313
|
+
for (let year = range.from; year <= range.to; year += 1) {
|
|
314
|
+
years.push(year);
|
|
315
|
+
}
|
|
316
|
+
return years;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/mutation.ts
|
|
320
|
+
var import_date6 = require("@internationalized/date");
|
|
321
|
+
function clampDate(ctx, date) {
|
|
322
|
+
return constrainValue(ctx, date);
|
|
323
|
+
}
|
|
324
|
+
function getTodayDate(timezone) {
|
|
325
|
+
return (0, import_date6.today)(timezone);
|
|
326
|
+
}
|
|
327
|
+
function getNextDay(date) {
|
|
328
|
+
return date.add({ days: 1 });
|
|
329
|
+
}
|
|
330
|
+
function getPreviousDay(date) {
|
|
331
|
+
return date.subtract({ days: 1 });
|
|
332
|
+
}
|
|
333
|
+
function setMonth(date, month) {
|
|
334
|
+
return date.set({ month });
|
|
335
|
+
}
|
|
336
|
+
function setYear(date, year) {
|
|
337
|
+
return date.set({ year });
|
|
338
|
+
}
|
|
339
|
+
function setCalendar(date, calendar) {
|
|
340
|
+
return (0, import_date6.toCalendar)((0, import_date6.toCalendarDate)(date), calendar);
|
|
341
|
+
}
|
|
342
|
+
function setDate(ctx, date, nextDate, startDate) {
|
|
343
|
+
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
|
+
}
|
|
352
|
+
return result;
|
|
353
|
+
}
|
|
354
|
+
function getPreviousAvailableDate(ctx, date, min) {
|
|
355
|
+
const minValue = min != null ? min : ctx.min;
|
|
356
|
+
if (!isDateUnavailable(ctx, date) || !minValue) {
|
|
357
|
+
return date;
|
|
358
|
+
}
|
|
359
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable(ctx, date)) {
|
|
360
|
+
date = date.subtract({ days: 1 });
|
|
361
|
+
}
|
|
362
|
+
if (date.compare(minValue) >= 0) {
|
|
363
|
+
return date;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// 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))
|
|
381
|
+
};
|
|
382
|
+
}
|
|
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
|
+
}
|
|
438
|
+
}
|
|
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
|
+
}
|
|
447
|
+
}
|
|
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 });
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/segment-constants.ts
|
|
459
|
+
var EDITABLE_SEGMENTS = {
|
|
460
|
+
year: true,
|
|
461
|
+
month: true,
|
|
462
|
+
day: true,
|
|
463
|
+
hour: true,
|
|
464
|
+
minute: true,
|
|
465
|
+
second: true,
|
|
466
|
+
dayPeriod: true,
|
|
467
|
+
era: true
|
|
468
|
+
};
|
|
469
|
+
var SEGMENT_PAGE_STEP = {
|
|
470
|
+
year: 5,
|
|
471
|
+
month: 2,
|
|
472
|
+
day: 7,
|
|
473
|
+
hour: 2,
|
|
474
|
+
minute: 15,
|
|
475
|
+
second: 15
|
|
476
|
+
};
|
|
477
|
+
function isSegmentEditable(segment) {
|
|
478
|
+
return EDITABLE_SEGMENTS[segment];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// src/segment-limit.ts
|
|
482
|
+
var import_date8 = require("@internationalized/date");
|
|
483
|
+
function getSegmentLimits(date, type, options) {
|
|
484
|
+
switch (type) {
|
|
485
|
+
case "era": {
|
|
486
|
+
let eras = date.calendar.getEras();
|
|
487
|
+
return {
|
|
488
|
+
value: eras.indexOf(date.era),
|
|
489
|
+
min: 0,
|
|
490
|
+
max: eras.length - 1
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
case "year":
|
|
494
|
+
return {
|
|
495
|
+
value: date.year,
|
|
496
|
+
min: 1,
|
|
497
|
+
max: date.calendar.getYearsInEra(date)
|
|
498
|
+
};
|
|
499
|
+
case "month":
|
|
500
|
+
return {
|
|
501
|
+
value: date.month,
|
|
502
|
+
min: (0, import_date8.getMinimumMonthInYear)(date),
|
|
503
|
+
max: date.calendar.getMonthsInYear(date)
|
|
504
|
+
};
|
|
505
|
+
case "day":
|
|
506
|
+
return {
|
|
507
|
+
value: date.day,
|
|
508
|
+
min: (0, import_date8.getMinimumDayInMonth)(date),
|
|
509
|
+
max: date.calendar.getDaysInMonth(date)
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
if ("hour" in date) {
|
|
513
|
+
switch (type) {
|
|
514
|
+
case "dayPeriod":
|
|
515
|
+
return {
|
|
516
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
517
|
+
min: 0,
|
|
518
|
+
max: 12
|
|
519
|
+
};
|
|
520
|
+
case "hour":
|
|
521
|
+
if (options.hour12) {
|
|
522
|
+
let isPM = date.hour >= 12;
|
|
523
|
+
return {
|
|
524
|
+
value: date.hour,
|
|
525
|
+
min: isPM ? 12 : 0,
|
|
526
|
+
max: isPM ? 23 : 11
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
value: date.hour,
|
|
531
|
+
min: 0,
|
|
532
|
+
max: 23
|
|
533
|
+
};
|
|
534
|
+
case "minute":
|
|
535
|
+
return {
|
|
536
|
+
value: date.minute,
|
|
537
|
+
min: 0,
|
|
538
|
+
max: 59
|
|
539
|
+
};
|
|
540
|
+
case "second":
|
|
541
|
+
return {
|
|
542
|
+
value: date.second,
|
|
543
|
+
min: 0,
|
|
544
|
+
max: 59
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return {};
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// src/segment-mutation.ts
|
|
552
|
+
function addSegment(date, part, amount, options) {
|
|
553
|
+
switch (part) {
|
|
554
|
+
case "era":
|
|
555
|
+
case "year":
|
|
556
|
+
case "month":
|
|
557
|
+
case "day":
|
|
558
|
+
return date.cycle(part, amount, { round: part === "year" });
|
|
559
|
+
}
|
|
560
|
+
if ("hour" in date) {
|
|
561
|
+
switch (part) {
|
|
562
|
+
case "dayPeriod": {
|
|
563
|
+
let hours = date.hour;
|
|
564
|
+
let isPM = hours >= 12;
|
|
565
|
+
return date.set({ hour: isPM ? hours - 12 : hours + 12 });
|
|
566
|
+
}
|
|
567
|
+
case "hour":
|
|
568
|
+
case "minute":
|
|
569
|
+
case "second":
|
|
570
|
+
return date.cycle(part, amount, {
|
|
571
|
+
round: part !== "hour",
|
|
572
|
+
hourCycle: options.hour12 ? 12 : 24
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function setSegment(date, part, value, options) {
|
|
578
|
+
switch (part) {
|
|
579
|
+
case "day":
|
|
580
|
+
case "month":
|
|
581
|
+
case "year":
|
|
582
|
+
case "era":
|
|
583
|
+
return date.set({ [part]: value });
|
|
584
|
+
}
|
|
585
|
+
if ("hour" in date) {
|
|
586
|
+
switch (part) {
|
|
587
|
+
case "dayPeriod": {
|
|
588
|
+
let hours = date.hour;
|
|
589
|
+
let wasPM = hours >= 12;
|
|
590
|
+
let isPM = value >= 12;
|
|
591
|
+
return isPM === wasPM ? date : date.set({ hour: wasPM ? hours - 12 : hours + 12 });
|
|
592
|
+
}
|
|
593
|
+
case "hour":
|
|
594
|
+
if (options.hour12) {
|
|
595
|
+
let hours = date.hour;
|
|
596
|
+
let wasPM = hours >= 12;
|
|
597
|
+
if (!wasPM && value === 12) {
|
|
598
|
+
value = 0;
|
|
599
|
+
}
|
|
600
|
+
if (wasPM && value < 12) {
|
|
601
|
+
value += 12;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
case "minute":
|
|
605
|
+
case "second":
|
|
606
|
+
return date.set({ [part]: value });
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
611
|
+
0 && (module.exports = {
|
|
612
|
+
SEGMENT_PAGE_STEP,
|
|
613
|
+
addSegment,
|
|
614
|
+
alignCenter,
|
|
615
|
+
alignDate,
|
|
616
|
+
alignEnd,
|
|
617
|
+
alignStart,
|
|
618
|
+
alignStartDate,
|
|
619
|
+
clampDate,
|
|
620
|
+
constrainStart,
|
|
621
|
+
constrainValue,
|
|
622
|
+
formatRange,
|
|
623
|
+
formatSelectedDate,
|
|
624
|
+
getDatesInWeek,
|
|
625
|
+
getEndDate,
|
|
626
|
+
getMonthDates,
|
|
627
|
+
getNextDay,
|
|
628
|
+
getNextPage,
|
|
629
|
+
getNextRow,
|
|
630
|
+
getNextSection,
|
|
631
|
+
getPreviousDay,
|
|
632
|
+
getPreviousPage,
|
|
633
|
+
getPreviousRow,
|
|
634
|
+
getPreviousSection,
|
|
635
|
+
getSectionEnd,
|
|
636
|
+
getSectionStart,
|
|
637
|
+
getSegmentLimits,
|
|
638
|
+
getTodayDate,
|
|
639
|
+
getUnitDuration,
|
|
640
|
+
getWeekDates,
|
|
641
|
+
getYearsRange,
|
|
642
|
+
isDateDisabled,
|
|
643
|
+
isDateEqual,
|
|
644
|
+
isDateInvalid,
|
|
645
|
+
isDateOutsideVisibleRange,
|
|
646
|
+
isDateUnavailable,
|
|
647
|
+
isNextVisibleRangeInvalid,
|
|
648
|
+
isPreviousVisibleRangeInvalid,
|
|
649
|
+
isSegmentEditable,
|
|
650
|
+
isTodayDate,
|
|
651
|
+
setCalendar,
|
|
652
|
+
setDate,
|
|
653
|
+
setMonth,
|
|
654
|
+
setSegment,
|
|
655
|
+
setYear
|
|
656
|
+
});
|