@zag-js/date-utils 0.1.3 → 0.1.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.
- package/dist/chunk-KBGJA6NB.mjs +55 -0
- package/dist/chunk-U3OBXRHI.mjs +42 -0
- package/dist/format-date.d.ts +9 -0
- package/dist/format-date.js +79 -0
- package/dist/format-date.mjs +6 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +93 -14
- package/dist/index.mjs +7 -3
- 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-UHOBXAHP.mjs +0 -17
- package/dist/conversion.d.ts +0 -5
- package/dist/conversion.js +0 -41
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CalendarDate } from '@internationalized/date';
|
|
2
|
+
|
|
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;
|
|
8
|
+
|
|
9
|
+
export { formatDate };
|
|
@@ -0,0 +1,79 @@
|
|
|
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/format-date.ts
|
|
21
|
+
var format_date_exports = {};
|
|
22
|
+
__export(format_date_exports, {
|
|
23
|
+
formatDate: () => formatDate
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(format_date_exports);
|
|
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;
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
formatDate
|
|
79
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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';
|
|
5
|
+
export { formatDate } from './format-date.js';
|
|
6
6
|
export { formatRange } from './format-range.js';
|
|
7
7
|
export { formatSelectedDate } from './format-selected-date.js';
|
|
8
8
|
export { formatVisibleRange } from './format-visible-range.js';
|
|
@@ -16,5 +16,6 @@ export { getWeekdayFormats } from './get-weekday-formats.js';
|
|
|
16
16
|
export { YearsRange, getYearsRange } from './get-year-range.js';
|
|
17
17
|
export { getNextDay, getPreviousAvailableDate, getPreviousDay, getTodayDate, setCalendar, setDate, setMonth, setYear } from './mutation.js';
|
|
18
18
|
export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart } from './pagination.js';
|
|
19
|
+
export { parseDateString } from './parse-date.js';
|
|
19
20
|
export { DateAdjustFn, DateGranularity } from './types.js';
|
|
20
21
|
import '@internationalized/date';
|
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,
|
|
@@ -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));
|
|
@@ -610,6 +649,45 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
610
649
|
});
|
|
611
650
|
}
|
|
612
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
|
+
}
|
|
613
691
|
// Annotate the CommonJS export names for ESM import in node:
|
|
614
692
|
0 && (module.exports = {
|
|
615
693
|
alignCenter,
|
|
@@ -619,6 +697,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
619
697
|
alignStartDate,
|
|
620
698
|
constrainStart,
|
|
621
699
|
constrainValue,
|
|
700
|
+
formatDate,
|
|
622
701
|
formatRange,
|
|
623
702
|
formatSelectedDate,
|
|
624
703
|
formatVisibleRange,
|
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,9 @@ import {
|
|
|
28
28
|
getSectionEnd,
|
|
29
29
|
getSectionStart
|
|
30
30
|
} from "./chunk-VTFZA34K.mjs";
|
|
31
|
+
import {
|
|
32
|
+
parseDateString
|
|
33
|
+
} from "./chunk-U3OBXRHI.mjs";
|
|
31
34
|
import {
|
|
32
35
|
getDecadeRange
|
|
33
36
|
} from "./chunk-G4VVKINZ.mjs";
|
|
@@ -60,13 +63,13 @@ 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
75
|
} from "./chunk-LQAXQPWP.mjs";
|
|
@@ -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,
|
|
@@ -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-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
|
-
});
|