@zag-js/date-utils 0.1.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/align.d.ts +3 -3
- package/dist/assertion.d.ts +7 -7
- package/dist/assertion.js +2 -2
- package/dist/assertion.mjs +1 -1
- package/dist/{chunk-ZZPZ2BFS.mjs → chunk-6FNTXW54.mjs} +8 -8
- package/dist/{chunk-LQAXQPWP.mjs → chunk-6LXTZHZP.mjs} +1 -1
- package/dist/{chunk-ODG5YF5H.mjs → chunk-FJKH6IJZ.mjs} +2 -2
- package/dist/{chunk-H4CAPQVS.mjs → chunk-HLAN6TUA.mjs} +2 -2
- package/dist/chunk-KBGJA6NB.mjs +55 -0
- package/dist/{chunk-CAYCTIEJ.mjs → chunk-KQVWH4YA.mjs} +1 -1
- package/dist/{chunk-KFJ757ZA.mjs → chunk-NV7UFBMY.mjs} +1 -3
- package/dist/{chunk-VTFZA34K.mjs → chunk-POBWDZPE.mjs} +2 -1
- package/dist/chunk-WQYMLJUJ.mjs +42 -0
- package/dist/constrain.d.ts +6 -6
- package/dist/duration.d.ts +3 -2
- package/dist/format-date.d.ts +9 -0
- package/dist/format-date.js +79 -0
- package/dist/format-date.mjs +6 -0
- package/dist/format-range.d.ts +2 -2
- package/dist/format-selected-date.d.ts +2 -2
- package/dist/format-selected-date.js +1 -1
- package/dist/format-selected-date.mjs +2 -2
- package/dist/format-visible-range.d.ts +2 -2
- package/dist/format-visible-range.js +1 -1
- package/dist/format-visible-range.mjs +2 -2
- package/dist/get-day-formatter.js +1 -1
- package/dist/get-day-formatter.mjs +1 -1
- package/dist/get-end-of-week.d.ts +3 -2
- package/dist/get-era-format.d.ts +2 -2
- package/dist/get-month-days.d.ts +3 -3
- package/dist/get-month-days.js +1 -3
- package/dist/get-month-days.mjs +1 -1
- package/dist/get-start-of-week.d.ts +3 -2
- package/dist/get-week-days.d.ts +4 -3
- package/dist/get-weekday-formats.d.ts +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +105 -27
- package/dist/index.mjs +14 -10
- package/dist/mutation.d.ts +10 -9
- package/dist/mutation.js +7 -7
- package/dist/mutation.mjs +1 -1
- package/dist/pagination.d.ts +40 -39
- package/dist/pagination.js +1 -0
- package/dist/pagination.mjs +2 -2
- package/dist/parse-date.d.ts +5 -0
- package/dist/parse-date.js +66 -0
- package/dist/{conversion.mjs → parse-date.mjs} +1 -1
- package/dist/types.d.ts +7 -7
- package/package.json +1 -1
- package/dist/chunk-UHOBXAHP.mjs +0 -17
- package/dist/conversion.d.ts +0 -5
- package/dist/conversion.js +0 -41
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(src_exports, {
|
|
|
27
27
|
alignStartDate: () => alignStartDate,
|
|
28
28
|
constrainStart: () => constrainStart,
|
|
29
29
|
constrainValue: () => constrainValue,
|
|
30
|
+
formatDate: () => formatDate,
|
|
30
31
|
formatRange: () => formatRange,
|
|
31
32
|
formatSelectedDate: () => formatSelectedDate,
|
|
32
33
|
formatVisibleRange: () => formatVisibleRange,
|
|
@@ -163,11 +164,11 @@ function isDateInvalid(date, minValue, maxValue) {
|
|
|
163
164
|
function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
|
|
164
165
|
return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(date, minValue, maxValue);
|
|
165
166
|
}
|
|
166
|
-
function isDateUnavailable(date, isUnavailable, minValue, maxValue) {
|
|
167
|
+
function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
|
|
167
168
|
if (!date) {
|
|
168
169
|
return false;
|
|
169
170
|
}
|
|
170
|
-
if (isUnavailable?.(date)) {
|
|
171
|
+
if (isUnavailable?.(date, locale)) {
|
|
171
172
|
return true;
|
|
172
173
|
}
|
|
173
174
|
return isDateInvalid(date, minValue, maxValue);
|
|
@@ -184,20 +185,6 @@ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
|
|
|
184
185
|
return (0, import_date2.isSameDay)(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
// src/conversion.ts
|
|
188
|
-
var import_date3 = require("@internationalized/date");
|
|
189
|
-
function parseDateString(value) {
|
|
190
|
-
try {
|
|
191
|
-
const date = new Date(value);
|
|
192
|
-
date.setMinutes(1e3);
|
|
193
|
-
if (isNaN(date.getTime()))
|
|
194
|
-
return;
|
|
195
|
-
const [dateWithoutTime] = date.toISOString().split("T");
|
|
196
|
-
return (0, import_date3.parseDate)(dateWithoutTime);
|
|
197
|
-
} catch {
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
188
|
// src/duration.ts
|
|
202
189
|
function getUnitDuration(duration) {
|
|
203
190
|
let d = { ...duration };
|
|
@@ -216,6 +203,58 @@ function getEndDate(startDate, duration) {
|
|
|
216
203
|
return startDate.add(d);
|
|
217
204
|
}
|
|
218
205
|
|
|
206
|
+
// src/format-date.ts
|
|
207
|
+
var import_date3 = require("@internationalized/date");
|
|
208
|
+
function createRegEx(sign) {
|
|
209
|
+
let symbols = "\\s|\\.|-|/|\\\\|,|\\$|\\!|\\?|:|;";
|
|
210
|
+
return new RegExp("(^|>|" + symbols + ")(" + sign + ")($|<|" + symbols + ")", "g");
|
|
211
|
+
}
|
|
212
|
+
function formatDate(value, formatString, locale, timeZone = "UTC") {
|
|
213
|
+
const datetime = (0, import_date3.toCalendarDateTime)(value);
|
|
214
|
+
const date = datetime.toDate(timeZone);
|
|
215
|
+
const formats = {
|
|
216
|
+
// Time in ms
|
|
217
|
+
T: date.getTime(),
|
|
218
|
+
// Minutes
|
|
219
|
+
m: date.toLocaleString(locale, { minute: "numeric" }),
|
|
220
|
+
mm: date.toLocaleString(locale, { minute: "2-digit" }),
|
|
221
|
+
// Seconds
|
|
222
|
+
s: date.toLocaleString(locale, { second: "numeric" }),
|
|
223
|
+
ss: date.toLocaleString(locale, { second: "2-digit" }),
|
|
224
|
+
// Hours
|
|
225
|
+
h: date.toLocaleString(locale, { hour: "numeric", hour12: true }),
|
|
226
|
+
hh: date.toLocaleString(locale, { hour: "2-digit", hour12: true }),
|
|
227
|
+
H: date.toLocaleString(locale, { hour: "numeric", hour12: false }),
|
|
228
|
+
HH: date.toLocaleString(locale, { hour: "2-digit", hour12: false }),
|
|
229
|
+
// Day period
|
|
230
|
+
aa: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLowerCase(),
|
|
231
|
+
AA: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toUpperCase(),
|
|
232
|
+
// Day of week
|
|
233
|
+
E: date.toLocaleString(locale, { weekday: "short" }),
|
|
234
|
+
EE: date.toLocaleString(locale, { weekday: "short" }),
|
|
235
|
+
EEE: date.toLocaleString(locale, { weekday: "short" }),
|
|
236
|
+
EEEE: date.toLocaleString(locale, { weekday: "long" }),
|
|
237
|
+
// Date of month
|
|
238
|
+
d: datetime.day,
|
|
239
|
+
dd: date.toLocaleString(locale, { day: "2-digit" }),
|
|
240
|
+
// Months
|
|
241
|
+
M: datetime.month + 1,
|
|
242
|
+
MM: date.toLocaleString(locale, { month: "2-digit" }),
|
|
243
|
+
MMM: date.toLocaleString(locale, { month: "short" }),
|
|
244
|
+
MMMM: date.toLocaleString(locale, { month: "long" }),
|
|
245
|
+
// Years
|
|
246
|
+
yy: date.toLocaleString(locale, { year: "2-digit" }),
|
|
247
|
+
yyyy: date.toLocaleString(locale, { year: "numeric" }),
|
|
248
|
+
YY: date.toLocaleString(locale, { year: "2-digit" }),
|
|
249
|
+
YYYY: date.toLocaleString(locale, { year: "numeric" })
|
|
250
|
+
};
|
|
251
|
+
let result = formatString;
|
|
252
|
+
for (const key in formats) {
|
|
253
|
+
result = result.replace(createRegEx(key), "$1" + formats[key] + "$3");
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
|
|
219
258
|
// src/format-range.ts
|
|
220
259
|
function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
221
260
|
let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
@@ -253,7 +292,7 @@ function getEraFormat(date) {
|
|
|
253
292
|
|
|
254
293
|
// src/get-day-formatter.ts
|
|
255
294
|
function getDayFormatter(locale, timeZone) {
|
|
256
|
-
const date = (0, import_date4.
|
|
295
|
+
const date = (0, import_date4.toCalendarDateTime)((0, import_date4.today)(timeZone));
|
|
257
296
|
return new import_date4.DateFormatter(locale, {
|
|
258
297
|
weekday: "long",
|
|
259
298
|
month: "long",
|
|
@@ -349,9 +388,7 @@ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
|
349
388
|
function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
|
|
350
389
|
const monthWeeks = (0, import_date9.getWeeksInMonth)(from, locale);
|
|
351
390
|
const weeks = [...new Array(numOfWeeks ?? monthWeeks).keys()];
|
|
352
|
-
return weeks.map((week) =>
|
|
353
|
-
return getDaysInWeek(week, from, locale, firstDayOfWeek);
|
|
354
|
-
});
|
|
391
|
+
return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
|
|
355
392
|
}
|
|
356
393
|
|
|
357
394
|
// src/get-month-names.ts
|
|
@@ -401,8 +438,8 @@ function getYearsRange(range) {
|
|
|
401
438
|
|
|
402
439
|
// src/mutation.ts
|
|
403
440
|
var import_date11 = require("@internationalized/date");
|
|
404
|
-
function getTodayDate(
|
|
405
|
-
return (0, import_date11.today)(
|
|
441
|
+
function getTodayDate(timeZone) {
|
|
442
|
+
return (0, import_date11.today)(timeZone ?? (0, import_date11.getLocalTimeZone)());
|
|
406
443
|
}
|
|
407
444
|
function getNextDay(date) {
|
|
408
445
|
return date.add({ days: 1 });
|
|
@@ -417,19 +454,19 @@ function setYear(date, year) {
|
|
|
417
454
|
return date.set({ year });
|
|
418
455
|
}
|
|
419
456
|
function setCalendar(date, calendar) {
|
|
420
|
-
return (0, import_date11.toCalendar)((0, import_date11.
|
|
457
|
+
return (0, import_date11.toCalendar)((0, import_date11.toCalendarDateTime)(date), calendar);
|
|
421
458
|
}
|
|
422
|
-
function setDate(date, startDate, isDateUnavailable2, minValue, maxValue) {
|
|
459
|
+
function setDate(date, startDate, isDateUnavailable2, locale, minValue, maxValue) {
|
|
423
460
|
let result;
|
|
424
461
|
result = constrainValue(date, minValue, maxValue);
|
|
425
|
-
result = getPreviousAvailableDate(date, startDate, isDateUnavailable2);
|
|
462
|
+
result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable2);
|
|
426
463
|
return result;
|
|
427
464
|
}
|
|
428
|
-
function getPreviousAvailableDate(date, minValue, isDateUnavailable2) {
|
|
465
|
+
function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable2) {
|
|
429
466
|
if (!isDateUnavailable2) {
|
|
430
467
|
return date;
|
|
431
468
|
}
|
|
432
|
-
while (date.compare(minValue) >= 0 && isDateUnavailable2(date)) {
|
|
469
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable2(date, locale)) {
|
|
433
470
|
date = date.subtract({ days: 1 });
|
|
434
471
|
}
|
|
435
472
|
if (date.compare(minValue) >= 0) {
|
|
@@ -551,6 +588,7 @@ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue
|
|
|
551
588
|
}
|
|
552
589
|
if (visibleDuration.weeks) {
|
|
553
590
|
return adjust({
|
|
591
|
+
//@ts-expect-error - endOfWeek is loosely typed
|
|
554
592
|
focusedDate: (0, import_date12.endOfWeek)(focusedDate, locale),
|
|
555
593
|
startDate
|
|
556
594
|
});
|
|
@@ -610,6 +648,45 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
610
648
|
});
|
|
611
649
|
}
|
|
612
650
|
}
|
|
651
|
+
|
|
652
|
+
// src/parse-date.ts
|
|
653
|
+
var import_date13 = require("@internationalized/date");
|
|
654
|
+
function parseDateString(date, locale, timeZone) {
|
|
655
|
+
const regex = createRegex(locale, timeZone);
|
|
656
|
+
const { year, month, day } = extract(regex, date) ?? {};
|
|
657
|
+
if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
|
|
658
|
+
return new import_date13.CalendarDateTime(+year, +month, +day);
|
|
659
|
+
}
|
|
660
|
+
const time = Date.parse(date);
|
|
661
|
+
if (!isNaN(time)) {
|
|
662
|
+
const date2 = new Date(time);
|
|
663
|
+
return new import_date13.CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function createRegex(locale, timeZone) {
|
|
667
|
+
const formatter = new import_date13.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
668
|
+
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
669
|
+
return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
|
|
670
|
+
}
|
|
671
|
+
function extract(pattern, str) {
|
|
672
|
+
const matches = str.match(pattern);
|
|
673
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
674
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
675
|
+
if (!groupMatches || groupMatches.length <= 0) {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
return group.match(/<(.+)>/)?.[1];
|
|
679
|
+
}).reduce((acc, curr, index) => {
|
|
680
|
+
if (!curr)
|
|
681
|
+
return acc;
|
|
682
|
+
if (matches && matches.length > index) {
|
|
683
|
+
acc[curr] = matches[index + 1];
|
|
684
|
+
} else {
|
|
685
|
+
acc[curr] = null;
|
|
686
|
+
}
|
|
687
|
+
return acc;
|
|
688
|
+
}, {});
|
|
689
|
+
}
|
|
613
690
|
// Annotate the CommonJS export names for ESM import in node:
|
|
614
691
|
0 && (module.exports = {
|
|
615
692
|
alignCenter,
|
|
@@ -619,6 +696,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
619
696
|
alignStartDate,
|
|
620
697
|
constrainStart,
|
|
621
698
|
constrainValue,
|
|
699
|
+
formatDate,
|
|
622
700
|
formatRange,
|
|
623
701
|
formatSelectedDate,
|
|
624
702
|
formatVisibleRange,
|
package/dist/index.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
setDate,
|
|
17
17
|
setMonth,
|
|
18
18
|
setYear
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-6FNTXW54.mjs";
|
|
20
20
|
import {
|
|
21
21
|
getAdjustedDateFn,
|
|
22
22
|
getNextPage,
|
|
@@ -27,14 +27,17 @@ import {
|
|
|
27
27
|
getPreviousSection,
|
|
28
28
|
getSectionEnd,
|
|
29
29
|
getSectionStart
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-POBWDZPE.mjs";
|
|
31
|
+
import {
|
|
32
|
+
parseDateString
|
|
33
|
+
} from "./chunk-WQYMLJUJ.mjs";
|
|
31
34
|
import {
|
|
32
35
|
getDecadeRange
|
|
33
36
|
} from "./chunk-G4VVKINZ.mjs";
|
|
34
37
|
import {
|
|
35
38
|
getDaysInWeek,
|
|
36
39
|
getMonthDays
|
|
37
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-NV7UFBMY.mjs";
|
|
38
41
|
import {
|
|
39
42
|
getMonthNames
|
|
40
43
|
} from "./chunk-5HGHDJ3L.mjs";
|
|
@@ -52,7 +55,7 @@ import {
|
|
|
52
55
|
isNextVisibleRangeInvalid,
|
|
53
56
|
isPreviousVisibleRangeInvalid,
|
|
54
57
|
isTodayDate
|
|
55
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-HLAN6TUA.mjs";
|
|
56
59
|
import {
|
|
57
60
|
alignCenter,
|
|
58
61
|
alignEnd,
|
|
@@ -60,28 +63,28 @@ import {
|
|
|
60
63
|
constrainStart,
|
|
61
64
|
constrainValue
|
|
62
65
|
} from "./chunk-MGPXEJO4.mjs";
|
|
63
|
-
import {
|
|
64
|
-
parseDateString
|
|
65
|
-
} from "./chunk-UHOBXAHP.mjs";
|
|
66
66
|
import {
|
|
67
67
|
getEndDate,
|
|
68
68
|
getUnitDuration
|
|
69
69
|
} from "./chunk-ZSLC7OI2.mjs";
|
|
70
|
+
import {
|
|
71
|
+
formatDate
|
|
72
|
+
} from "./chunk-KBGJA6NB.mjs";
|
|
70
73
|
import {
|
|
71
74
|
formatSelectedDate
|
|
72
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-6LXTZHZP.mjs";
|
|
73
76
|
import {
|
|
74
77
|
formatRange
|
|
75
78
|
} from "./chunk-HKHGJ6WS.mjs";
|
|
76
79
|
import {
|
|
77
80
|
formatVisibleRange
|
|
78
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-KQVWH4YA.mjs";
|
|
79
82
|
import {
|
|
80
83
|
getMonthFormatter
|
|
81
84
|
} from "./chunk-LGEGBP3O.mjs";
|
|
82
85
|
import {
|
|
83
86
|
getDayFormatter
|
|
84
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-FJKH6IJZ.mjs";
|
|
85
88
|
import "./chunk-KN3YMOSL.mjs";
|
|
86
89
|
export {
|
|
87
90
|
alignCenter,
|
|
@@ -91,6 +94,7 @@ export {
|
|
|
91
94
|
alignStartDate,
|
|
92
95
|
constrainStart,
|
|
93
96
|
constrainValue,
|
|
97
|
+
formatDate,
|
|
94
98
|
formatRange,
|
|
95
99
|
formatSelectedDate,
|
|
96
100
|
formatVisibleRange,
|
package/dist/mutation.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
+
import { DateValue, Calendar } from '@internationalized/date';
|
|
2
3
|
import { DateAvailableFn } from './types.js';
|
|
3
4
|
|
|
4
|
-
declare function getTodayDate(
|
|
5
|
-
declare function getNextDay(date:
|
|
6
|
-
declare function getPreviousDay(date:
|
|
7
|
-
declare function setMonth(date:
|
|
8
|
-
declare function setYear(date:
|
|
9
|
-
declare function setCalendar(date:
|
|
10
|
-
declare function setDate(date:
|
|
11
|
-
declare function getPreviousAvailableDate(date:
|
|
5
|
+
declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
|
|
6
|
+
declare function getNextDay(date: DateValue): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
7
|
+
declare function getPreviousDay(date: DateValue): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
8
|
+
declare function setMonth(date: DateValue, month: number): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
9
|
+
declare function setYear(date: DateValue, year: number): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
10
|
+
declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
11
|
+
declare function setDate(date: DateValue, startDate: DateValue, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue, maxValue: DateValue): DateValue | undefined;
|
|
12
|
+
declare function getPreviousAvailableDate(date: DateValue, minValue: DateValue, locale: string, isDateUnavailable?: DateAvailableFn): DateValue | undefined;
|
|
12
13
|
|
|
13
14
|
export { getNextDay, getPreviousAvailableDate, getPreviousDay, getTodayDate, setCalendar, setDate, setMonth, setYear };
|
package/dist/mutation.js
CHANGED
|
@@ -45,8 +45,8 @@ function constrainValue(date, minValue, maxValue) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// src/mutation.ts
|
|
48
|
-
function getTodayDate(
|
|
49
|
-
return (0, import_date2.today)(
|
|
48
|
+
function getTodayDate(timeZone) {
|
|
49
|
+
return (0, import_date2.today)(timeZone ?? (0, import_date2.getLocalTimeZone)());
|
|
50
50
|
}
|
|
51
51
|
function getNextDay(date) {
|
|
52
52
|
return date.add({ days: 1 });
|
|
@@ -61,19 +61,19 @@ function setYear(date, year) {
|
|
|
61
61
|
return date.set({ year });
|
|
62
62
|
}
|
|
63
63
|
function setCalendar(date, calendar) {
|
|
64
|
-
return (0, import_date2.toCalendar)((0, import_date2.
|
|
64
|
+
return (0, import_date2.toCalendar)((0, import_date2.toCalendarDateTime)(date), calendar);
|
|
65
65
|
}
|
|
66
|
-
function setDate(date, startDate, isDateUnavailable, minValue, maxValue) {
|
|
66
|
+
function setDate(date, startDate, isDateUnavailable, locale, minValue, maxValue) {
|
|
67
67
|
let result;
|
|
68
68
|
result = constrainValue(date, minValue, maxValue);
|
|
69
|
-
result = getPreviousAvailableDate(date, startDate, isDateUnavailable);
|
|
69
|
+
result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable);
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
72
|
-
function getPreviousAvailableDate(date, minValue, isDateUnavailable) {
|
|
72
|
+
function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable) {
|
|
73
73
|
if (!isDateUnavailable) {
|
|
74
74
|
return date;
|
|
75
75
|
}
|
|
76
|
-
while (date.compare(minValue) >= 0 && isDateUnavailable(date)) {
|
|
76
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable(date, locale)) {
|
|
77
77
|
date = date.subtract({ days: 1 });
|
|
78
78
|
}
|
|
79
79
|
if (date.compare(minValue) >= 0) {
|
package/dist/mutation.mjs
CHANGED
package/dist/pagination.d.ts
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
+
import { DateDuration, DateValue } from '@internationalized/date';
|
|
2
3
|
|
|
3
|
-
declare function getAdjustedDateFn(visibleDuration: DateDuration, locale: string, minValue?:
|
|
4
|
-
startDate:
|
|
5
|
-
focusedDate:
|
|
4
|
+
declare function getAdjustedDateFn(visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): (options: {
|
|
5
|
+
startDate: DateValue;
|
|
6
|
+
focusedDate: DateValue;
|
|
6
7
|
}) => {
|
|
7
|
-
startDate:
|
|
8
|
-
focusedDate:
|
|
9
|
-
endDate: CalendarDate;
|
|
8
|
+
startDate: DateValue;
|
|
9
|
+
focusedDate: DateValue;
|
|
10
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
10
11
|
};
|
|
11
|
-
declare function getNextPage(focusedDate:
|
|
12
|
-
startDate:
|
|
13
|
-
focusedDate:
|
|
14
|
-
endDate: CalendarDate;
|
|
12
|
+
declare function getNextPage(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
13
|
+
startDate: DateValue;
|
|
14
|
+
focusedDate: DateValue;
|
|
15
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
15
16
|
};
|
|
16
|
-
declare function getPreviousPage(focusedDate:
|
|
17
|
-
startDate:
|
|
18
|
-
focusedDate:
|
|
19
|
-
endDate: CalendarDate;
|
|
17
|
+
declare function getPreviousPage(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
18
|
+
startDate: DateValue;
|
|
19
|
+
focusedDate: DateValue;
|
|
20
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
20
21
|
};
|
|
21
|
-
declare function getNextRow(focusedDate:
|
|
22
|
-
startDate:
|
|
23
|
-
focusedDate:
|
|
24
|
-
endDate: CalendarDate;
|
|
22
|
+
declare function getNextRow(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
23
|
+
startDate: DateValue;
|
|
24
|
+
focusedDate: DateValue;
|
|
25
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
25
26
|
} | undefined;
|
|
26
|
-
declare function getPreviousRow(focusedDate:
|
|
27
|
-
startDate:
|
|
28
|
-
focusedDate:
|
|
29
|
-
endDate: CalendarDate;
|
|
27
|
+
declare function getPreviousRow(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
28
|
+
startDate: DateValue;
|
|
29
|
+
focusedDate: DateValue;
|
|
30
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
30
31
|
} | undefined;
|
|
31
|
-
declare function getSectionStart(focusedDate:
|
|
32
|
-
startDate:
|
|
33
|
-
focusedDate:
|
|
34
|
-
endDate: CalendarDate;
|
|
32
|
+
declare function getSectionStart(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
33
|
+
startDate: DateValue;
|
|
34
|
+
focusedDate: DateValue;
|
|
35
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
35
36
|
} | undefined;
|
|
36
|
-
declare function getSectionEnd(focusedDate:
|
|
37
|
-
startDate:
|
|
38
|
-
focusedDate:
|
|
39
|
-
endDate: CalendarDate;
|
|
37
|
+
declare function getSectionEnd(focusedDate: DateValue, startDate: DateValue, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
38
|
+
startDate: DateValue;
|
|
39
|
+
focusedDate: DateValue;
|
|
40
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
40
41
|
} | undefined;
|
|
41
|
-
declare function getNextSection(focusedDate:
|
|
42
|
-
startDate:
|
|
43
|
-
focusedDate:
|
|
44
|
-
endDate: CalendarDate;
|
|
42
|
+
declare function getNextSection(focusedDate: DateValue, startDate: DateValue, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
43
|
+
startDate: DateValue;
|
|
44
|
+
focusedDate: DateValue;
|
|
45
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
45
46
|
} | undefined;
|
|
46
|
-
declare function getPreviousSection(focusedDate:
|
|
47
|
-
startDate:
|
|
48
|
-
focusedDate:
|
|
49
|
-
endDate: CalendarDate;
|
|
47
|
+
declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: DateValue, maxValue?: DateValue): {
|
|
48
|
+
startDate: DateValue;
|
|
49
|
+
focusedDate: DateValue;
|
|
50
|
+
endDate: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
50
51
|
} | undefined;
|
|
51
52
|
|
|
52
53
|
export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
|
package/dist/pagination.js
CHANGED
|
@@ -216,6 +216,7 @@ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue
|
|
|
216
216
|
}
|
|
217
217
|
if (visibleDuration.weeks) {
|
|
218
218
|
return adjust({
|
|
219
|
+
//@ts-expect-error - endOfWeek is loosely typed
|
|
219
220
|
focusedDate: (0, import_date3.endOfWeek)(focusedDate, locale),
|
|
220
221
|
startDate
|
|
221
222
|
});
|
package/dist/pagination.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
getPreviousSection,
|
|
9
9
|
getSectionEnd,
|
|
10
10
|
getSectionStart
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-POBWDZPE.mjs";
|
|
12
|
+
import "./chunk-HLAN6TUA.mjs";
|
|
13
13
|
import "./chunk-MGPXEJO4.mjs";
|
|
14
14
|
import "./chunk-ZSLC7OI2.mjs";
|
|
15
15
|
export {
|
|
@@ -0,0 +1,66 @@
|
|
|
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/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) {
|
|
28
|
+
const regex = createRegex(locale, timeZone);
|
|
29
|
+
const { year, month, day } = extract(regex, date) ?? {};
|
|
30
|
+
if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
|
|
31
|
+
return new import_date.CalendarDateTime(+year, +month, +day);
|
|
32
|
+
}
|
|
33
|
+
const time = Date.parse(date);
|
|
34
|
+
if (!isNaN(time)) {
|
|
35
|
+
const date2 = new Date(time);
|
|
36
|
+
return new import_date.CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function createRegex(locale, timeZone) {
|
|
40
|
+
const formatter = new import_date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
41
|
+
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
42
|
+
return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
|
|
43
|
+
}
|
|
44
|
+
function extract(pattern, str) {
|
|
45
|
+
const matches = str.match(pattern);
|
|
46
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
47
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
48
|
+
if (!groupMatches || groupMatches.length <= 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return group.match(/<(.+)>/)?.[1];
|
|
52
|
+
}).reduce((acc, curr, index) => {
|
|
53
|
+
if (!curr)
|
|
54
|
+
return acc;
|
|
55
|
+
if (matches && matches.length > index) {
|
|
56
|
+
acc[curr] = matches[index + 1];
|
|
57
|
+
} else {
|
|
58
|
+
acc[curr] = null;
|
|
59
|
+
}
|
|
60
|
+
return acc;
|
|
61
|
+
}, {});
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
parseDateString
|
|
66
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { DateFormatter, DateValue
|
|
1
|
+
import { DateFormatter, DateValue } from '@internationalized/date';
|
|
2
2
|
|
|
3
3
|
type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
4
4
|
type DateAlignment = "start" | "end" | "center";
|
|
5
5
|
type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
6
|
-
type DateAvailableFn = (date: DateValue) => boolean;
|
|
6
|
+
type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
7
7
|
type GetPlaceholderFn = (options: {
|
|
8
8
|
field: string;
|
|
9
9
|
locale: string;
|
|
10
10
|
}) => string;
|
|
11
11
|
type DateAdjustFn = (options: {
|
|
12
|
-
startDate:
|
|
13
|
-
focusedDate:
|
|
12
|
+
startDate: DateValue;
|
|
13
|
+
focusedDate: DateValue;
|
|
14
14
|
}) => {
|
|
15
|
-
startDate:
|
|
16
|
-
focusedDate:
|
|
17
|
-
endDate:
|
|
15
|
+
startDate: DateValue;
|
|
16
|
+
focusedDate: DateValue;
|
|
17
|
+
endDate: DateValue;
|
|
18
18
|
};
|
|
19
19
|
type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
20
20
|
|
package/package.json
CHANGED
package/dist/chunk-UHOBXAHP.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/conversion.ts
|
|
2
|
-
import { parseDate } from "@internationalized/date";
|
|
3
|
-
function parseDateString(value) {
|
|
4
|
-
try {
|
|
5
|
-
const date = new Date(value);
|
|
6
|
-
date.setMinutes(1e3);
|
|
7
|
-
if (isNaN(date.getTime()))
|
|
8
|
-
return;
|
|
9
|
-
const [dateWithoutTime] = date.toISOString().split("T");
|
|
10
|
-
return parseDate(dateWithoutTime);
|
|
11
|
-
} catch {
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
parseDateString
|
|
17
|
-
};
|