@zag-js/date-utils 0.0.0-dev-20230327180246 → 0.0.0-dev-20230328140202
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/chunk-KBGJA6NB.mjs +55 -0
- package/dist/chunk-U3OBXRHI.mjs +42 -0
- package/dist/format-date.d.ts +5 -1
- package/dist/format-date.js +49 -3
- package/dist/format-date.mjs +1 -1
- package/dist/format-selected-date.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +88 -17
- package/dist/index.mjs +14 -14
- 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/package.json +1 -1
- package/dist/chunk-J22B5EMX.mjs +0 -9
- package/dist/chunk-UHOBXAHP.mjs +0 -17
- package/dist/conversion.d.ts +0 -5
- package/dist/conversion.js +0 -41
- package/dist/{chunk-LOHO72U6.mjs → chunk-LQAXQPWP.mjs} +3 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/format-date.ts
|
|
2
|
+
import { toCalendarDateTime } from "@internationalized/date";
|
|
3
|
+
function createRegEx(sign) {
|
|
4
|
+
let symbols = "\\s|\\.|-|/|\\\\|,|\\$|\\!|\\?|:|;";
|
|
5
|
+
return new RegExp("(^|>|" + symbols + ")(" + sign + ")($|<|" + symbols + ")", "g");
|
|
6
|
+
}
|
|
7
|
+
function formatDate(value, formatString, locale, timeZone = "UTC") {
|
|
8
|
+
const datetime = toCalendarDateTime(value);
|
|
9
|
+
const date = datetime.toDate(timeZone);
|
|
10
|
+
const formats = {
|
|
11
|
+
// Time in ms
|
|
12
|
+
T: date.getTime(),
|
|
13
|
+
// Minutes
|
|
14
|
+
m: date.toLocaleString(locale, { minute: "numeric" }),
|
|
15
|
+
mm: date.toLocaleString(locale, { minute: "2-digit" }),
|
|
16
|
+
// Seconds
|
|
17
|
+
s: date.toLocaleString(locale, { second: "numeric" }),
|
|
18
|
+
ss: date.toLocaleString(locale, { second: "2-digit" }),
|
|
19
|
+
// Hours
|
|
20
|
+
h: date.toLocaleString(locale, { hour: "numeric", hour12: true }),
|
|
21
|
+
hh: date.toLocaleString(locale, { hour: "2-digit", hour12: true }),
|
|
22
|
+
H: date.toLocaleString(locale, { hour: "numeric", hour12: false }),
|
|
23
|
+
HH: date.toLocaleString(locale, { hour: "2-digit", hour12: false }),
|
|
24
|
+
// Day period
|
|
25
|
+
aa: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLowerCase(),
|
|
26
|
+
AA: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toUpperCase(),
|
|
27
|
+
// Day of week
|
|
28
|
+
E: date.toLocaleString(locale, { weekday: "short" }),
|
|
29
|
+
EE: date.toLocaleString(locale, { weekday: "short" }),
|
|
30
|
+
EEE: date.toLocaleString(locale, { weekday: "short" }),
|
|
31
|
+
EEEE: date.toLocaleString(locale, { weekday: "long" }),
|
|
32
|
+
// Date of month
|
|
33
|
+
d: datetime.day,
|
|
34
|
+
dd: date.toLocaleString(locale, { day: "2-digit" }),
|
|
35
|
+
// Months
|
|
36
|
+
M: datetime.month + 1,
|
|
37
|
+
MM: date.toLocaleString(locale, { month: "2-digit" }),
|
|
38
|
+
MMM: date.toLocaleString(locale, { month: "short" }),
|
|
39
|
+
MMMM: date.toLocaleString(locale, { month: "long" }),
|
|
40
|
+
// Years
|
|
41
|
+
yy: date.toLocaleString(locale, { year: "2-digit" }),
|
|
42
|
+
yyyy: date.toLocaleString(locale, { year: "numeric" }),
|
|
43
|
+
YY: date.toLocaleString(locale, { year: "2-digit" }),
|
|
44
|
+
YYYY: date.toLocaleString(locale, { year: "numeric" })
|
|
45
|
+
};
|
|
46
|
+
let result = formatString;
|
|
47
|
+
for (const key in formats) {
|
|
48
|
+
result = result.replace(createRegEx(key), "$1" + formats[key] + "$3");
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
formatDate
|
|
55
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/parse-date.ts
|
|
2
|
+
import { CalendarDate, DateFormatter } from "@internationalized/date";
|
|
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 CalendarDate(+year, +month, +day);
|
|
8
|
+
}
|
|
9
|
+
const time = Date.parse(date);
|
|
10
|
+
if (!isNaN(time)) {
|
|
11
|
+
const date2 = new Date(time);
|
|
12
|
+
return new CalendarDate(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 {
|
|
41
|
+
parseDateString
|
|
42
|
+
};
|
package/dist/format-date.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { CalendarDate } from '@internationalized/date';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Formats a date using the given format string as defined in:
|
|
5
|
+
* https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
6
|
+
*/
|
|
7
|
+
declare function formatDate(value: CalendarDate, formatString: string, locale: string, timeZone?: string): string;
|
|
4
8
|
|
|
5
9
|
export { formatDate };
|
package/dist/format-date.js
CHANGED
|
@@ -23,9 +23,55 @@ __export(format_date_exports, {
|
|
|
23
23
|
formatDate: () => formatDate
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(format_date_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
var import_date = require("@internationalized/date");
|
|
27
|
+
function createRegEx(sign) {
|
|
28
|
+
let symbols = "\\s|\\.|-|/|\\\\|,|\\$|\\!|\\?|:|;";
|
|
29
|
+
return new RegExp("(^|>|" + symbols + ")(" + sign + ")($|<|" + symbols + ")", "g");
|
|
30
|
+
}
|
|
31
|
+
function formatDate(value, formatString, locale, timeZone = "UTC") {
|
|
32
|
+
const datetime = (0, import_date.toCalendarDateTime)(value);
|
|
33
|
+
const date = datetime.toDate(timeZone);
|
|
34
|
+
const formats = {
|
|
35
|
+
// Time in ms
|
|
36
|
+
T: date.getTime(),
|
|
37
|
+
// Minutes
|
|
38
|
+
m: date.toLocaleString(locale, { minute: "numeric" }),
|
|
39
|
+
mm: date.toLocaleString(locale, { minute: "2-digit" }),
|
|
40
|
+
// Seconds
|
|
41
|
+
s: date.toLocaleString(locale, { second: "numeric" }),
|
|
42
|
+
ss: date.toLocaleString(locale, { second: "2-digit" }),
|
|
43
|
+
// Hours
|
|
44
|
+
h: date.toLocaleString(locale, { hour: "numeric", hour12: true }),
|
|
45
|
+
hh: date.toLocaleString(locale, { hour: "2-digit", hour12: true }),
|
|
46
|
+
H: date.toLocaleString(locale, { hour: "numeric", hour12: false }),
|
|
47
|
+
HH: date.toLocaleString(locale, { hour: "2-digit", hour12: false }),
|
|
48
|
+
// Day period
|
|
49
|
+
aa: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLowerCase(),
|
|
50
|
+
AA: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toUpperCase(),
|
|
51
|
+
// Day of week
|
|
52
|
+
E: date.toLocaleString(locale, { weekday: "short" }),
|
|
53
|
+
EE: date.toLocaleString(locale, { weekday: "short" }),
|
|
54
|
+
EEE: date.toLocaleString(locale, { weekday: "short" }),
|
|
55
|
+
EEEE: date.toLocaleString(locale, { weekday: "long" }),
|
|
56
|
+
// Date of month
|
|
57
|
+
d: datetime.day,
|
|
58
|
+
dd: date.toLocaleString(locale, { day: "2-digit" }),
|
|
59
|
+
// Months
|
|
60
|
+
M: datetime.month + 1,
|
|
61
|
+
MM: date.toLocaleString(locale, { month: "2-digit" }),
|
|
62
|
+
MMM: date.toLocaleString(locale, { month: "short" }),
|
|
63
|
+
MMMM: date.toLocaleString(locale, { month: "long" }),
|
|
64
|
+
// Years
|
|
65
|
+
yy: date.toLocaleString(locale, { year: "2-digit" }),
|
|
66
|
+
yyyy: date.toLocaleString(locale, { year: "numeric" }),
|
|
67
|
+
YY: date.toLocaleString(locale, { year: "2-digit" }),
|
|
68
|
+
YYYY: date.toLocaleString(locale, { year: "numeric" })
|
|
69
|
+
};
|
|
70
|
+
let result = formatString;
|
|
71
|
+
for (const key in formats) {
|
|
72
|
+
result = result.replace(createRegEx(key), "$1" + formats[key] + "$3");
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
29
75
|
}
|
|
30
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
77
|
0 && (module.exports = {
|
package/dist/format-date.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatSelectedDate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LQAXQPWP.mjs";
|
|
4
|
+
import "./chunk-HKHGJ6WS.mjs";
|
|
4
5
|
import "./chunk-ODG5YF5H.mjs";
|
|
5
6
|
import "./chunk-KN3YMOSL.mjs";
|
|
6
|
-
import "./chunk-HKHGJ6WS.mjs";
|
|
7
7
|
export {
|
|
8
8
|
formatSelectedDate
|
|
9
9
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { alignDate, alignStartDate } from './align.js';
|
|
2
2
|
export { isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, isTodayDate } from './assertion.js';
|
|
3
3
|
export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue } from './constrain.js';
|
|
4
|
-
export { parseDateString } from './conversion.js';
|
|
5
4
|
export { getEndDate, getUnitDuration } from './duration.js';
|
|
6
5
|
export { formatDate } from './format-date.js';
|
|
7
6
|
export { formatRange } from './format-range.js';
|
|
@@ -17,5 +16,6 @@ export { getWeekdayFormats } from './get-weekday-formats.js';
|
|
|
17
16
|
export { YearsRange, getYearsRange } from './get-year-range.js';
|
|
18
17
|
export { getNextDay, getPreviousAvailableDate, getPreviousDay, getTodayDate, setCalendar, setDate, setMonth, setYear } from './mutation.js';
|
|
19
18
|
export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart } from './pagination.js';
|
|
19
|
+
export { parseDateString } from './parse-date.js';
|
|
20
20
|
export { DateAdjustFn, DateGranularity } from './types.js';
|
|
21
21
|
import '@internationalized/date';
|
package/dist/index.js
CHANGED
|
@@ -185,20 +185,6 @@ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
|
|
|
185
185
|
return (0, import_date2.isSameDay)(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
// src/conversion.ts
|
|
189
|
-
var import_date3 = require("@internationalized/date");
|
|
190
|
-
function parseDateString(value) {
|
|
191
|
-
try {
|
|
192
|
-
const date = new Date(value);
|
|
193
|
-
date.setMinutes(1e3);
|
|
194
|
-
if (isNaN(date.getTime()))
|
|
195
|
-
return;
|
|
196
|
-
const [dateWithoutTime] = date.toISOString().split("T");
|
|
197
|
-
return (0, import_date3.parseDate)(dateWithoutTime);
|
|
198
|
-
} catch {
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
188
|
// src/duration.ts
|
|
203
189
|
function getUnitDuration(duration) {
|
|
204
190
|
let d = { ...duration };
|
|
@@ -218,9 +204,55 @@ function getEndDate(startDate, duration) {
|
|
|
218
204
|
}
|
|
219
205
|
|
|
220
206
|
// src/format-date.ts
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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;
|
|
224
256
|
}
|
|
225
257
|
|
|
226
258
|
// src/format-range.ts
|
|
@@ -617,6 +649,45 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
617
649
|
});
|
|
618
650
|
}
|
|
619
651
|
}
|
|
652
|
+
|
|
653
|
+
// src/parse-date.ts
|
|
654
|
+
var import_date13 = require("@internationalized/date");
|
|
655
|
+
function parseDateString(date, locale, timeZone) {
|
|
656
|
+
const regex = createRegex(locale, timeZone);
|
|
657
|
+
const { year, month, day } = extract(regex, date) ?? {};
|
|
658
|
+
if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
|
|
659
|
+
return new import_date13.CalendarDate(+year, +month, +day);
|
|
660
|
+
}
|
|
661
|
+
const time = Date.parse(date);
|
|
662
|
+
if (!isNaN(time)) {
|
|
663
|
+
const date2 = new Date(time);
|
|
664
|
+
return new import_date13.CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
function createRegex(locale, timeZone) {
|
|
668
|
+
const formatter = new import_date13.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
669
|
+
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
670
|
+
return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
|
|
671
|
+
}
|
|
672
|
+
function extract(pattern, str) {
|
|
673
|
+
const matches = str.match(pattern);
|
|
674
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
675
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
676
|
+
if (!groupMatches || groupMatches.length <= 0) {
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
return group.match(/<(.+)>/)?.[1];
|
|
680
|
+
}).reduce((acc, curr, index) => {
|
|
681
|
+
if (!curr)
|
|
682
|
+
return acc;
|
|
683
|
+
if (matches && matches.length > index) {
|
|
684
|
+
acc[curr] = matches[index + 1];
|
|
685
|
+
} else {
|
|
686
|
+
acc[curr] = null;
|
|
687
|
+
}
|
|
688
|
+
return acc;
|
|
689
|
+
}, {});
|
|
690
|
+
}
|
|
620
691
|
// Annotate the CommonJS export names for ESM import in node:
|
|
621
692
|
0 && (module.exports = {
|
|
622
693
|
alignCenter,
|
package/dist/index.mjs
CHANGED
|
@@ -29,8 +29,8 @@ import {
|
|
|
29
29
|
getSectionStart
|
|
30
30
|
} from "./chunk-VTFZA34K.mjs";
|
|
31
31
|
import {
|
|
32
|
-
|
|
33
|
-
} from "./chunk-
|
|
32
|
+
parseDateString
|
|
33
|
+
} from "./chunk-U3OBXRHI.mjs";
|
|
34
34
|
import {
|
|
35
35
|
getDecadeRange
|
|
36
36
|
} from "./chunk-G4VVKINZ.mjs";
|
|
@@ -38,13 +38,10 @@ import {
|
|
|
38
38
|
getDaysInWeek,
|
|
39
39
|
getMonthDays
|
|
40
40
|
} from "./chunk-KFJ757ZA.mjs";
|
|
41
|
-
import "./chunk-SI75FOJ2.mjs";
|
|
42
|
-
import {
|
|
43
|
-
getMonthFormatter
|
|
44
|
-
} from "./chunk-LGEGBP3O.mjs";
|
|
45
41
|
import {
|
|
46
42
|
getMonthNames
|
|
47
43
|
} from "./chunk-5HGHDJ3L.mjs";
|
|
44
|
+
import "./chunk-SI75FOJ2.mjs";
|
|
48
45
|
import {
|
|
49
46
|
alignDate,
|
|
50
47
|
alignStartDate
|
|
@@ -66,26 +63,29 @@ import {
|
|
|
66
63
|
constrainStart,
|
|
67
64
|
constrainValue
|
|
68
65
|
} from "./chunk-MGPXEJO4.mjs";
|
|
69
|
-
import {
|
|
70
|
-
parseDateString
|
|
71
|
-
} from "./chunk-UHOBXAHP.mjs";
|
|
72
66
|
import {
|
|
73
67
|
getEndDate,
|
|
74
68
|
getUnitDuration
|
|
75
69
|
} from "./chunk-ZSLC7OI2.mjs";
|
|
76
70
|
import {
|
|
77
71
|
formatDate
|
|
78
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-KBGJA6NB.mjs";
|
|
79
73
|
import {
|
|
80
74
|
formatSelectedDate
|
|
81
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-LQAXQPWP.mjs";
|
|
76
|
+
import {
|
|
77
|
+
formatRange
|
|
78
|
+
} from "./chunk-HKHGJ6WS.mjs";
|
|
79
|
+
import {
|
|
80
|
+
formatVisibleRange
|
|
81
|
+
} from "./chunk-CAYCTIEJ.mjs";
|
|
82
|
+
import {
|
|
83
|
+
getMonthFormatter
|
|
84
|
+
} from "./chunk-LGEGBP3O.mjs";
|
|
82
85
|
import {
|
|
83
86
|
getDayFormatter
|
|
84
87
|
} from "./chunk-ODG5YF5H.mjs";
|
|
85
88
|
import "./chunk-KN3YMOSL.mjs";
|
|
86
|
-
import {
|
|
87
|
-
formatRange
|
|
88
|
-
} from "./chunk-HKHGJ6WS.mjs";
|
|
89
89
|
export {
|
|
90
90
|
alignCenter,
|
|
91
91
|
alignDate,
|
|
@@ -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.CalendarDate(+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.CalendarDate(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/package.json
CHANGED
package/dist/chunk-J22B5EMX.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// src/format-date.ts
|
|
2
|
-
function formatDate(date, formatString, locale, timeZone = "UTC") {
|
|
3
|
-
const nativeDate = date.toDate(timeZone);
|
|
4
|
-
return formatString.replace(/yyyy/gi, nativeDate.toLocaleString(locale, { year: "numeric", timeZone })).replace(/yy/gi, nativeDate.toLocaleString(locale, { year: "2-digit", timeZone })).replace(/dd/gi, nativeDate.toLocaleString(locale, { day: "2-digit", timeZone })).replace(/d/gi, nativeDate.toLocaleString(locale, { day: "numeric", timeZone })).replace(/mmmm/gi, nativeDate.toLocaleString(locale, { month: "long", timeZone })).replace(/mmm/gi, nativeDate.toLocaleString(locale, { month: "short", timeZone })).replace(/mm/gi, nativeDate.toLocaleString(locale, { month: "2-digit", timeZone })).replace(/m/gi, nativeDate.toLocaleString(locale, { month: "numeric", timeZone }));
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
formatDate
|
|
9
|
-
};
|
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
|
-
};
|
package/dist/conversion.d.ts
DELETED
package/dist/conversion.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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/conversion.ts
|
|
21
|
-
var conversion_exports = {};
|
|
22
|
-
__export(conversion_exports, {
|
|
23
|
-
parseDateString: () => parseDateString
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(conversion_exports);
|
|
26
|
-
var import_date = require("@internationalized/date");
|
|
27
|
-
function parseDateString(value) {
|
|
28
|
-
try {
|
|
29
|
-
const date = new Date(value);
|
|
30
|
-
date.setMinutes(1e3);
|
|
31
|
-
if (isNaN(date.getTime()))
|
|
32
|
-
return;
|
|
33
|
-
const [dateWithoutTime] = date.toISOString().split("T");
|
|
34
|
-
return (0, import_date.parseDate)(dateWithoutTime);
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
-
0 && (module.exports = {
|
|
40
|
-
parseDateString
|
|
41
|
-
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getDayFormatter
|
|
3
|
-
} from "./chunk-ODG5YF5H.mjs";
|
|
4
1
|
import {
|
|
5
2
|
formatRange
|
|
6
3
|
} from "./chunk-HKHGJ6WS.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getDayFormatter
|
|
6
|
+
} from "./chunk-ODG5YF5H.mjs";
|
|
7
7
|
|
|
8
8
|
// src/format-selected-date.ts
|
|
9
9
|
import { isSameDay } from "@internationalized/date";
|