@zag-js/date-utils 0.1.2 → 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-5HGHDJ3L.mjs +14 -0
- package/dist/chunk-AMZ7CJ5F.mjs +18 -0
- package/dist/chunk-CAYCTIEJ.mjs +29 -0
- package/dist/chunk-G4VVKINZ.mjs +14 -0
- package/dist/chunk-KBGJA6NB.mjs +55 -0
- package/dist/chunk-KFJ757ZA.mjs +32 -0
- package/dist/chunk-KLHRN7WS.mjs +20 -0
- package/dist/chunk-KN3YMOSL.mjs +8 -0
- package/dist/chunk-LGEGBP3O.mjs +20 -0
- package/dist/{chunk-NXMEZINO.mjs → chunk-LQAXQPWP.mjs} +4 -7
- package/dist/chunk-ODG5YF5H.mjs +21 -0
- package/dist/chunk-SI75FOJ2.mjs +11 -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/format-selected-date.d.ts +1 -2
- package/dist/format-selected-date.js +14 -14
- package/dist/format-selected-date.mjs +3 -2
- package/dist/format-visible-range.d.ts +1 -2
- package/dist/format-visible-range.js +29 -50
- package/dist/format-visible-range.mjs +4 -3
- package/dist/get-day-formatter.d.ts +5 -0
- package/dist/{placeholder.js → get-day-formatter.js} +22 -21
- package/dist/get-day-formatter.mjs +7 -0
- package/dist/get-decade-range.d.ts +3 -0
- package/dist/get-decade-range.js +38 -0
- package/dist/get-decade-range.mjs +6 -0
- package/dist/get-end-of-week.d.ts +5 -0
- package/dist/{segment-constants.js → get-end-of-week.js} +17 -32
- package/dist/get-end-of-week.mjs +11 -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-month-days.d.ts +6 -0
- package/dist/{get-month-dates.js → get-month-days.js} +26 -27
- package/dist/get-month-days.mjs +9 -0
- package/dist/get-month-formatter.d.ts +5 -0
- package/dist/{get-formatter.js → get-month-formatter.js} +14 -26
- package/dist/get-month-formatter.mjs +7 -0
- package/dist/get-month-names.d.ts +3 -0
- package/dist/get-month-names.js +38 -0
- package/dist/get-month-names.mjs +6 -0
- package/dist/get-start-of-week.d.ts +5 -0
- package/dist/get-start-of-week.js +35 -0
- package/dist/get-start-of-week.mjs +6 -0
- package/dist/get-week-days.d.ts +10 -0
- package/dist/get-week-days.js +62 -0
- package/dist/get-week-days.mjs +8 -0
- package/dist/get-weekday-formats.d.ts +10 -0
- package/dist/get-weekday-formats.js +44 -0
- package/dist/get-weekday-formats.mjs +6 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +223 -307
- package/dist/index.mjs +40 -41
- package/dist/parse-date.d.ts +5 -0
- package/dist/parse-date.js +66 -0
- package/dist/parse-date.mjs +6 -0
- package/dist/types.d.ts +1 -2
- package/package.json +2 -2
- package/dist/chunk-55BYHK5B.mjs +0 -31
- package/dist/chunk-DZM5JUL2.mjs +0 -22
- package/dist/chunk-ETRHBIGD.mjs +0 -66
- package/dist/chunk-GLQDJRSE.mjs +0 -31
- package/dist/chunk-JZVHAOWX.mjs +0 -35
- package/dist/chunk-MGRIF22W.mjs +0 -18
- package/dist/chunk-SQCHVCXH.mjs +0 -42
- package/dist/chunk-TSOWYV6W.mjs +0 -34
- package/dist/chunk-U6WRBS5P.mjs +0 -77
- package/dist/get-formatter.d.ts +0 -8
- package/dist/get-formatter.mjs +0 -8
- package/dist/get-month-dates.d.ts +0 -5
- package/dist/get-month-dates.mjs +0 -7
- package/dist/get-week-dates.d.ts +0 -7
- package/dist/get-week-dates.js +0 -60
- package/dist/get-week-dates.mjs +0 -8
- package/dist/placeholder.d.ts +0 -7
- package/dist/placeholder.mjs +0 -8
- package/dist/segment-constants.d.ts +0 -27
- package/dist/segment-constants.mjs +0 -10
- package/dist/segment-limit.d.ts +0 -10
- package/dist/segment-limit.js +0 -101
- package/dist/segment-limit.mjs +0 -6
- package/dist/segment-mutation.d.ts +0 -7
- package/dist/segment-mutation.js +0 -91
- package/dist/segment-mutation.mjs +0 -8
- package/dist/segment-parts.d.ts +0 -27
- package/dist/segment-parts.js +0 -159
- package/dist/segment-parts.mjs +0 -11
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/get-month-names.ts
|
|
2
|
+
function getMonthNames(locale, format = "long") {
|
|
3
|
+
const date = new Date(2021, 0, 1);
|
|
4
|
+
const monthNames = [];
|
|
5
|
+
for (let i = 0; i < 12; i++) {
|
|
6
|
+
monthNames.push(date.toLocaleString(locale, { month: format }));
|
|
7
|
+
date.setMonth(date.getMonth() + 1);
|
|
8
|
+
}
|
|
9
|
+
return monthNames;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
getMonthNames
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getWeekdayFormats
|
|
3
|
+
} from "./chunk-KLHRN7WS.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getStartOfWeek
|
|
6
|
+
} from "./chunk-SI75FOJ2.mjs";
|
|
7
|
+
|
|
8
|
+
// src/get-week-days.ts
|
|
9
|
+
function getWeekDays(date, startOfWeekProp, timeZone, locale) {
|
|
10
|
+
const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
|
|
11
|
+
const weeks = [...new Array(7).keys()];
|
|
12
|
+
const format = getWeekdayFormats(locale, timeZone);
|
|
13
|
+
return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
getWeekDays
|
|
18
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getMonthFormatter
|
|
3
|
+
} from "./chunk-LGEGBP3O.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getDayFormatter
|
|
6
|
+
} from "./chunk-ODG5YF5H.mjs";
|
|
7
|
+
|
|
8
|
+
// src/format-visible-range.ts
|
|
9
|
+
import { endOfMonth, isSameDay, startOfMonth } from "@internationalized/date";
|
|
10
|
+
function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
11
|
+
const start = startDate;
|
|
12
|
+
const end = endDate ?? startDate;
|
|
13
|
+
const dayFormatter = getDayFormatter(locale, timeZone);
|
|
14
|
+
if (!isSameDay(start, startOfMonth(start))) {
|
|
15
|
+
return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
16
|
+
}
|
|
17
|
+
const monthFormatter = getMonthFormatter(locale, timeZone);
|
|
18
|
+
if (isSameDay(end, endOfMonth(start))) {
|
|
19
|
+
return monthFormatter.format(start.toDate(timeZone));
|
|
20
|
+
}
|
|
21
|
+
if (isSameDay(end, endOfMonth(end))) {
|
|
22
|
+
return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
23
|
+
}
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
formatVisibleRange
|
|
29
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/get-decade-range.ts
|
|
2
|
+
function getDecadeRange(year) {
|
|
3
|
+
const computedYear = year - year % 10 - 1;
|
|
4
|
+
const years = [];
|
|
5
|
+
for (let i = 0; i < 12; i += 1) {
|
|
6
|
+
const value = computedYear + i;
|
|
7
|
+
years.push(value);
|
|
8
|
+
}
|
|
9
|
+
return years;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
getDecadeRange
|
|
14
|
+
};
|
|
@@ -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,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getStartOfWeek
|
|
3
|
+
} from "./chunk-SI75FOJ2.mjs";
|
|
4
|
+
|
|
5
|
+
// src/get-month-days.ts
|
|
6
|
+
import { getWeeksInMonth, isSameDay } from "@internationalized/date";
|
|
7
|
+
function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
8
|
+
const weekDate = from.add({ weeks: weekIndex });
|
|
9
|
+
const dates = [];
|
|
10
|
+
let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
|
|
11
|
+
while (dates.length < 7) {
|
|
12
|
+
dates.push(date);
|
|
13
|
+
let nextDate = date.add({ days: 1 });
|
|
14
|
+
if (isSameDay(date, nextDate)) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
date = nextDate;
|
|
18
|
+
}
|
|
19
|
+
return dates;
|
|
20
|
+
}
|
|
21
|
+
function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
|
|
22
|
+
const monthWeeks = getWeeksInMonth(from, locale);
|
|
23
|
+
const weeks = [...new Array(numOfWeeks ?? monthWeeks).keys()];
|
|
24
|
+
return weeks.map((week) => {
|
|
25
|
+
return getDaysInWeek(week, from, locale, firstDayOfWeek);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
getDaysInWeek,
|
|
31
|
+
getMonthDays
|
|
32
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/get-weekday-formats.ts
|
|
2
|
+
import { DateFormatter } from "@internationalized/date";
|
|
3
|
+
function getWeekdayFormats(locale, timeZone) {
|
|
4
|
+
const longFormat = new DateFormatter(locale, { weekday: "long", timeZone });
|
|
5
|
+
const shortFormat = new DateFormatter(locale, { weekday: "short", timeZone });
|
|
6
|
+
const narrowFormat = new DateFormatter(locale, { weekday: "narrow", timeZone });
|
|
7
|
+
return (value) => {
|
|
8
|
+
const date = value instanceof Date ? value : value.toDate(timeZone);
|
|
9
|
+
return {
|
|
10
|
+
value,
|
|
11
|
+
short: shortFormat.format(date),
|
|
12
|
+
long: longFormat.format(date),
|
|
13
|
+
narrow: narrowFormat.format(date)
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
getWeekdayFormats
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEraFormat
|
|
3
|
+
} from "./chunk-KN3YMOSL.mjs";
|
|
4
|
+
|
|
5
|
+
// src/get-month-formatter.ts
|
|
6
|
+
import { today, toCalendarDate, DateFormatter } from "@internationalized/date";
|
|
7
|
+
function getMonthFormatter(locale, timeZone) {
|
|
8
|
+
const date = toCalendarDate(today(timeZone));
|
|
9
|
+
return new DateFormatter(locale, {
|
|
10
|
+
month: "long",
|
|
11
|
+
year: "numeric",
|
|
12
|
+
era: getEraFormat(date),
|
|
13
|
+
calendar: date?.calendar.identifier,
|
|
14
|
+
timeZone
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
getMonthFormatter
|
|
20
|
+
};
|
|
@@ -2,18 +2,15 @@ import {
|
|
|
2
2
|
formatRange
|
|
3
3
|
} from "./chunk-HKHGJ6WS.mjs";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
getDayFormatter
|
|
6
|
+
} from "./chunk-ODG5YF5H.mjs";
|
|
7
7
|
|
|
8
8
|
// src/format-selected-date.ts
|
|
9
9
|
import { isSameDay } from "@internationalized/date";
|
|
10
|
-
function formatSelectedDate(startDate, endDate,
|
|
10
|
+
function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
11
11
|
let start = startDate;
|
|
12
12
|
let end = endDate ?? startDate;
|
|
13
|
-
let formatter =
|
|
14
|
-
if (isSelectingRange || start == null || end == null) {
|
|
15
|
-
return "";
|
|
16
|
-
}
|
|
13
|
+
let formatter = getDayFormatter(locale, timeZone);
|
|
17
14
|
if (isSameDay(start, end)) {
|
|
18
15
|
return formatter.format(start.toDate(timeZone));
|
|
19
16
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEraFormat
|
|
3
|
+
} from "./chunk-KN3YMOSL.mjs";
|
|
4
|
+
|
|
5
|
+
// src/get-day-formatter.ts
|
|
6
|
+
import { DateFormatter, toCalendarDate, today } from "@internationalized/date";
|
|
7
|
+
function getDayFormatter(locale, timeZone) {
|
|
8
|
+
const date = toCalendarDate(today(timeZone));
|
|
9
|
+
return new DateFormatter(locale, {
|
|
10
|
+
weekday: "long",
|
|
11
|
+
month: "long",
|
|
12
|
+
year: "numeric",
|
|
13
|
+
day: "numeric",
|
|
14
|
+
era: getEraFormat(date),
|
|
15
|
+
timeZone
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
getDayFormatter
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/get-start-of-week.ts
|
|
2
|
+
import { getDayOfWeek } from "@internationalized/date";
|
|
3
|
+
function getStartOfWeek(date, locale, firstDayOfWeek = 0) {
|
|
4
|
+
const day = getDayOfWeek(date, locale);
|
|
5
|
+
const diff = (day - firstDayOfWeek + 7) % 7;
|
|
6
|
+
return date.subtract({ days: diff });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
getStartOfWeek
|
|
11
|
+
};
|
|
@@ -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
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CalendarDate } from '@internationalized/date';
|
|
2
|
-
import { GetFormatterFn } from './types.js';
|
|
3
2
|
|
|
4
|
-
declare function formatSelectedDate(startDate: CalendarDate, endDate: CalendarDate | null,
|
|
3
|
+
declare function formatSelectedDate(startDate: CalendarDate, endDate: CalendarDate | null, locale: string, timeZone: string): string;
|
|
5
4
|
|
|
6
5
|
export { formatSelectedDate };
|
|
@@ -23,7 +23,7 @@ __export(format_selected_date_exports, {
|
|
|
23
23
|
formatSelectedDate: () => formatSelectedDate
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(format_selected_date_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_date2 = require("@internationalized/date");
|
|
27
27
|
|
|
28
28
|
// src/format-range.ts
|
|
29
29
|
function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
@@ -49,33 +49,33 @@ function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
|
49
49
|
return toString(start, end);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// src/get-formatter.ts
|
|
52
|
+
// src/get-day-formatter.ts
|
|
53
|
+
var import_date = require("@internationalized/date");
|
|
54
|
+
|
|
55
|
+
// src/get-era-format.ts
|
|
53
56
|
function getEraFormat(date) {
|
|
54
57
|
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
59
|
+
|
|
60
|
+
// src/get-day-formatter.ts
|
|
61
|
+
function getDayFormatter(locale, timeZone) {
|
|
62
|
+
const date = (0, import_date.toCalendarDate)((0, import_date.today)(timeZone));
|
|
63
|
+
return new import_date.DateFormatter(locale, {
|
|
61
64
|
weekday: "long",
|
|
62
65
|
month: "long",
|
|
63
66
|
year: "numeric",
|
|
64
67
|
day: "numeric",
|
|
65
|
-
era,
|
|
68
|
+
era: getEraFormat(date),
|
|
66
69
|
timeZone
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
// src/format-selected-date.ts
|
|
71
|
-
function formatSelectedDate(startDate, endDate,
|
|
74
|
+
function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
72
75
|
let start = startDate;
|
|
73
76
|
let end = endDate ?? startDate;
|
|
74
|
-
let formatter =
|
|
75
|
-
if (
|
|
76
|
-
return "";
|
|
77
|
-
}
|
|
78
|
-
if ((0, import_date.isSameDay)(start, end)) {
|
|
77
|
+
let formatter = getDayFormatter(locale, timeZone);
|
|
78
|
+
if ((0, import_date2.isSameDay)(start, end)) {
|
|
79
79
|
return formatter.format(start.toDate(timeZone));
|
|
80
80
|
}
|
|
81
81
|
return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatSelectedDate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LQAXQPWP.mjs";
|
|
4
4
|
import "./chunk-HKHGJ6WS.mjs";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-ODG5YF5H.mjs";
|
|
6
|
+
import "./chunk-KN3YMOSL.mjs";
|
|
6
7
|
export {
|
|
7
8
|
formatSelectedDate
|
|
8
9
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CalendarDate } from '@internationalized/date';
|
|
2
|
-
import { GetFormatterFn } from './types.js';
|
|
3
2
|
|
|
4
|
-
declare function formatVisibleRange(startDate: CalendarDate
|
|
3
|
+
declare function formatVisibleRange(startDate: CalendarDate, endDate: CalendarDate | null, locale: string, timeZone: string): string;
|
|
5
4
|
|
|
6
5
|
export { formatVisibleRange };
|
|
@@ -23,79 +23,58 @@ __export(format_visible_range_exports, {
|
|
|
23
23
|
formatVisibleRange: () => formatVisibleRange
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(format_visible_range_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_date3 = require("@internationalized/date");
|
|
27
27
|
|
|
28
|
-
// src/
|
|
29
|
-
|
|
30
|
-
let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
31
|
-
let separatorIndex = -1;
|
|
32
|
-
for (let i = 0; i < parts.length; i++) {
|
|
33
|
-
let part = parts[i];
|
|
34
|
-
if (part.source === "shared" && part.type === "literal") {
|
|
35
|
-
separatorIndex = i;
|
|
36
|
-
} else if (part.source === "endRange") {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
let start = "";
|
|
41
|
-
let end = "";
|
|
42
|
-
for (let i = 0; i < parts.length; i++) {
|
|
43
|
-
if (i < separatorIndex) {
|
|
44
|
-
start += parts[i].value;
|
|
45
|
-
} else if (i > separatorIndex) {
|
|
46
|
-
end += parts[i].value;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return toString(start, end);
|
|
50
|
-
}
|
|
28
|
+
// src/get-day-formatter.ts
|
|
29
|
+
var import_date = require("@internationalized/date");
|
|
51
30
|
|
|
52
|
-
// src/get-
|
|
31
|
+
// src/get-era-format.ts
|
|
53
32
|
function getEraFormat(date) {
|
|
54
33
|
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
55
34
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
35
|
+
|
|
36
|
+
// src/get-day-formatter.ts
|
|
37
|
+
function getDayFormatter(locale, timeZone) {
|
|
38
|
+
const date = (0, import_date.toCalendarDate)((0, import_date.today)(timeZone));
|
|
39
|
+
return new import_date.DateFormatter(locale, {
|
|
61
40
|
weekday: "long",
|
|
62
41
|
month: "long",
|
|
63
42
|
year: "numeric",
|
|
64
43
|
day: "numeric",
|
|
65
|
-
era,
|
|
44
|
+
era: getEraFormat(date),
|
|
66
45
|
timeZone
|
|
67
46
|
});
|
|
68
47
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
|
|
49
|
+
// src/get-month-formatter.ts
|
|
50
|
+
var import_date2 = require("@internationalized/date");
|
|
51
|
+
function getMonthFormatter(locale, timeZone) {
|
|
52
|
+
const date = (0, import_date2.toCalendarDate)((0, import_date2.today)(timeZone));
|
|
53
|
+
return new import_date2.DateFormatter(locale, {
|
|
74
54
|
month: "long",
|
|
75
55
|
year: "numeric",
|
|
76
|
-
era,
|
|
77
|
-
calendar:
|
|
56
|
+
era: getEraFormat(date),
|
|
57
|
+
calendar: date?.calendar.identifier,
|
|
78
58
|
timeZone
|
|
79
59
|
});
|
|
80
60
|
}
|
|
81
61
|
|
|
82
62
|
// src/format-visible-range.ts
|
|
83
|
-
function formatVisibleRange(startDate, endDate,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
let dateFormatter = getDateFormatter(start, end, getFormatter, timeZone);
|
|
90
|
-
if (!(0, import_date.isSameDay)(start, (0, import_date.startOfMonth)(start))) {
|
|
91
|
-
return isAria ? formatRange(start, end, dateFormatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone) : dateFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
63
|
+
function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
64
|
+
const start = startDate;
|
|
65
|
+
const end = endDate ?? startDate;
|
|
66
|
+
const dayFormatter = getDayFormatter(locale, timeZone);
|
|
67
|
+
if (!(0, import_date3.isSameDay)(start, (0, import_date3.startOfMonth)(start))) {
|
|
68
|
+
return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
92
69
|
}
|
|
93
|
-
|
|
70
|
+
const monthFormatter = getMonthFormatter(locale, timeZone);
|
|
71
|
+
if ((0, import_date3.isSameDay)(end, (0, import_date3.endOfMonth)(start))) {
|
|
94
72
|
return monthFormatter.format(start.toDate(timeZone));
|
|
95
73
|
}
|
|
96
|
-
if ((0,
|
|
97
|
-
return
|
|
74
|
+
if ((0, import_date3.isSameDay)(end, (0, import_date3.endOfMonth)(end))) {
|
|
75
|
+
return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
|
|
98
76
|
}
|
|
77
|
+
return "";
|
|
99
78
|
}
|
|
100
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
101
80
|
0 && (module.exports = {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatVisibleRange
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-CAYCTIEJ.mjs";
|
|
4
|
+
import "./chunk-LGEGBP3O.mjs";
|
|
5
|
+
import "./chunk-ODG5YF5H.mjs";
|
|
6
|
+
import "./chunk-KN3YMOSL.mjs";
|
|
6
7
|
export {
|
|
7
8
|
formatVisibleRange
|
|
8
9
|
};
|