@zag-js/date-utils 1.34.1 → 1.35.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.
Files changed (61) hide show
  1. package/dist/align.d.mts +8 -0
  2. package/dist/align.d.ts +8 -0
  3. package/dist/align.js +52 -0
  4. package/dist/align.mjs +26 -0
  5. package/dist/assertion.d.mts +10 -0
  6. package/dist/assertion.d.ts +10 -0
  7. package/dist/assertion.js +58 -0
  8. package/dist/assertion.mjs +29 -0
  9. package/dist/constrain.d.mts +9 -0
  10. package/dist/constrain.d.ts +9 -0
  11. package/dist/constrain.js +109 -0
  12. package/dist/constrain.mjs +87 -0
  13. package/dist/date-month.d.mts +23 -0
  14. package/dist/date-month.d.ts +23 -0
  15. package/dist/date-month.js +131 -0
  16. package/dist/date-month.mjs +105 -0
  17. package/dist/date-year.d.mts +14 -0
  18. package/dist/date-year.d.ts +14 -0
  19. package/dist/date-year.js +72 -0
  20. package/dist/date-year.mjs +44 -0
  21. package/dist/duration.d.mts +13 -0
  22. package/dist/duration.d.ts +13 -0
  23. package/dist/duration.js +42 -0
  24. package/dist/duration.mjs +16 -0
  25. package/dist/format.d.mts +8 -0
  26. package/dist/format.d.ts +8 -0
  27. package/dist/format.js +83 -0
  28. package/dist/format.mjs +56 -0
  29. package/dist/formatter.d.mts +6 -0
  30. package/dist/formatter.d.ts +6 -0
  31. package/dist/formatter.js +55 -0
  32. package/dist/formatter.mjs +29 -0
  33. package/dist/get-era-format.d.mts +6 -0
  34. package/dist/get-era-format.d.ts +6 -0
  35. package/dist/get-era-format.js +37 -0
  36. package/dist/get-era-format.mjs +12 -0
  37. package/dist/index.d.mts +14 -103
  38. package/dist/index.d.ts +14 -103
  39. package/dist/index.js +46 -637
  40. package/dist/index.mjs +13 -591
  41. package/dist/mutation.d.mts +10 -0
  42. package/dist/mutation.d.ts +10 -0
  43. package/dist/mutation.js +62 -0
  44. package/dist/mutation.mjs +39 -0
  45. package/dist/pagination.d.mts +21 -0
  46. package/dist/pagination.d.ts +21 -0
  47. package/dist/pagination.js +220 -0
  48. package/dist/pagination.mjs +187 -0
  49. package/dist/parse-date.d.mts +6 -0
  50. package/dist/parse-date.d.ts +6 -0
  51. package/dist/parse-date.js +79 -0
  52. package/dist/parse-date.mjs +54 -0
  53. package/dist/preset.d.mts +6 -0
  54. package/dist/preset.d.ts +6 -0
  55. package/dist/preset.js +66 -0
  56. package/dist/preset.mjs +50 -0
  57. package/dist/types.d.mts +23 -0
  58. package/dist/types.d.ts +23 -0
  59. package/dist/types.js +18 -0
  60. package/dist/types.mjs +0 -0
  61. package/package.json +1 -1
@@ -0,0 +1,105 @@
1
+ // src/date-month.ts
2
+ import {
3
+ DateFormatter,
4
+ endOfWeek,
5
+ getWeeksInMonth,
6
+ isSameDay,
7
+ startOfWeek
8
+ } from "@internationalized/date";
9
+ var daysOfTheWeek = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
10
+ function normalizeFirstDayOfWeek(firstDayOfWeek) {
11
+ return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
12
+ }
13
+ function getStartOfWeek(date, locale, firstDayOfWeek) {
14
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
15
+ return startOfWeek(date, locale, firstDay);
16
+ }
17
+ function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
18
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
19
+ return endOfWeek(date, locale, firstDay);
20
+ }
21
+ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
22
+ const weekDate = from.add({ weeks: weekIndex });
23
+ const dates = [];
24
+ let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
25
+ while (dates.length < 7) {
26
+ dates.push(date);
27
+ let nextDate = date.add({ days: 1 });
28
+ if (isSameDay(date, nextDate)) break;
29
+ date = nextDate;
30
+ }
31
+ return dates;
32
+ }
33
+ function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
34
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
35
+ const monthWeeks = numOfWeeks ?? getWeeksInMonth(from, locale, firstDay);
36
+ const weeks = [...new Array(monthWeeks).keys()];
37
+ return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
38
+ }
39
+ function getWeekdayFormats(locale, timeZone) {
40
+ const longFormat = new DateFormatter(locale, { weekday: "long", timeZone });
41
+ const shortFormat = new DateFormatter(locale, { weekday: "short", timeZone });
42
+ const narrowFormat = new DateFormatter(locale, { weekday: "narrow", timeZone });
43
+ return (value) => {
44
+ const date = value instanceof Date ? value : value.toDate(timeZone);
45
+ return {
46
+ value,
47
+ short: shortFormat.format(date),
48
+ long: longFormat.format(date),
49
+ narrow: narrowFormat.format(date)
50
+ };
51
+ };
52
+ }
53
+ function getWeekDays(date, startOfWeekProp, timeZone, locale) {
54
+ const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
55
+ const weeks = [...new Array(7).keys()];
56
+ const format = getWeekdayFormats(locale, timeZone);
57
+ return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
58
+ }
59
+ function getMonthNames(locale, format = "long", referenceDate) {
60
+ if (!referenceDate || referenceDate.calendar.identifier === "gregory" || referenceDate.calendar.identifier === "iso8601") {
61
+ const date = new Date(2021, 0, 1);
62
+ const monthNames2 = [];
63
+ for (let i = 0; i < 12; i++) {
64
+ monthNames2.push(date.toLocaleString(locale, { month: format }));
65
+ date.setMonth(date.getMonth() + 1);
66
+ }
67
+ return monthNames2;
68
+ }
69
+ const monthCount = referenceDate.calendar.getMonthsInYear(referenceDate);
70
+ const formatter = new DateFormatter(locale, {
71
+ month: format,
72
+ calendar: referenceDate.calendar.identifier
73
+ });
74
+ const monthNames = [];
75
+ for (let month = 1; month <= monthCount; month++) {
76
+ const d = referenceDate.set({ month });
77
+ monthNames.push(formatter.format(d.toDate("UTC")));
78
+ }
79
+ return monthNames;
80
+ }
81
+ function getWeekOfYear(date, locale) {
82
+ const mondayOfWeek = startOfWeek(date, locale, "mon");
83
+ const year = mondayOfWeek.year;
84
+ const jan4 = mondayOfWeek.set({ month: 1, day: 4 });
85
+ const week1Monday = startOfWeek(jan4, locale, "mon");
86
+ const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
87
+ const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
88
+ if (julianMonday >= julianWeek1) {
89
+ return 1 + Math.floor((julianMonday - julianWeek1) / 7);
90
+ }
91
+ const prevJan4 = mondayOfWeek.set({ year: year - 1, month: 1, day: 4 });
92
+ const prevWeek1Monday = startOfWeek(prevJan4, locale, "mon");
93
+ const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
94
+ return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
95
+ }
96
+ export {
97
+ getDaysInWeek,
98
+ getEndOfWeek,
99
+ getMonthDays,
100
+ getMonthNames,
101
+ getStartOfWeek,
102
+ getWeekDays,
103
+ getWeekOfYear,
104
+ getWeekdayFormats
105
+ };
@@ -0,0 +1,14 @@
1
+ import { DateValue } from '@internationalized/date';
2
+
3
+ interface YearsRange {
4
+ from: number;
5
+ to: number;
6
+ }
7
+ declare function getYearsRange(range: YearsRange): number[];
8
+ declare function getDefaultYearRange(referenceDate: DateValue, min?: DateValue, max?: DateValue): YearsRange;
9
+ declare function normalizeYear(year: string | null | undefined): string | undefined;
10
+ declare function getDecadeRange(year: number, opts?: {
11
+ strict?: boolean;
12
+ }): number[];
13
+
14
+ export { type YearsRange, getDecadeRange, getDefaultYearRange, getYearsRange, normalizeYear };
@@ -0,0 +1,14 @@
1
+ import { DateValue } from '@internationalized/date';
2
+
3
+ interface YearsRange {
4
+ from: number;
5
+ to: number;
6
+ }
7
+ declare function getYearsRange(range: YearsRange): number[];
8
+ declare function getDefaultYearRange(referenceDate: DateValue, min?: DateValue, max?: DateValue): YearsRange;
9
+ declare function normalizeYear(year: string | null | undefined): string | undefined;
10
+ declare function getDecadeRange(year: number, opts?: {
11
+ strict?: boolean;
12
+ }): number[];
13
+
14
+ export { type YearsRange, getDecadeRange, getDefaultYearRange, getYearsRange, normalizeYear };
@@ -0,0 +1,72 @@
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/date-year.ts
21
+ var date_year_exports = {};
22
+ __export(date_year_exports, {
23
+ getDecadeRange: () => getDecadeRange,
24
+ getDefaultYearRange: () => getDefaultYearRange,
25
+ getYearsRange: () => getYearsRange,
26
+ normalizeYear: () => normalizeYear
27
+ });
28
+ module.exports = __toCommonJS(date_year_exports);
29
+ var import_date = require("@internationalized/date");
30
+ function getYearsRange(range) {
31
+ const years = [];
32
+ for (let year = range.from; year <= range.to; year += 1) years.push(year);
33
+ return years;
34
+ }
35
+ var DEFAULT_MIN_YEAR = 1900;
36
+ var DEFAULT_MAX_YEAR = 2099;
37
+ function getDefaultYearRange(referenceDate, min, max) {
38
+ const calendar = referenceDate.calendar;
39
+ const fromYear = min?.year ?? (0, import_date.toCalendar)(new import_date.CalendarDate(DEFAULT_MIN_YEAR, 1, 1), calendar).year;
40
+ const toYear = max?.year ?? (0, import_date.toCalendar)(new import_date.CalendarDate(DEFAULT_MAX_YEAR, 12, 31), calendar).year;
41
+ return { from: fromYear, to: toYear };
42
+ }
43
+ var FUTURE_YEAR_COERCION = 10;
44
+ function normalizeYear(year) {
45
+ if (!year) return;
46
+ if (year.length === 3) return year.padEnd(4, "0");
47
+ if (year.length === 2) {
48
+ const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
49
+ const currentCentury = Math.floor(currentYear / 100) * 100;
50
+ const twoDigitYear = parseInt(year.slice(-2), 10);
51
+ const fullYear = currentCentury + twoDigitYear;
52
+ return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
53
+ }
54
+ return year;
55
+ }
56
+ function getDecadeRange(year, opts) {
57
+ const chunkSize = opts?.strict ? 10 : 12;
58
+ const computedYear = year - year % 10;
59
+ const years = [];
60
+ for (let i = 0; i < chunkSize; i += 1) {
61
+ const value = computedYear + i;
62
+ years.push(value);
63
+ }
64
+ return years;
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ getDecadeRange,
69
+ getDefaultYearRange,
70
+ getYearsRange,
71
+ normalizeYear
72
+ });
@@ -0,0 +1,44 @@
1
+ // src/date-year.ts
2
+ import { CalendarDate, toCalendar } from "@internationalized/date";
3
+ function getYearsRange(range) {
4
+ const years = [];
5
+ for (let year = range.from; year <= range.to; year += 1) years.push(year);
6
+ return years;
7
+ }
8
+ var DEFAULT_MIN_YEAR = 1900;
9
+ var DEFAULT_MAX_YEAR = 2099;
10
+ function getDefaultYearRange(referenceDate, min, max) {
11
+ const calendar = referenceDate.calendar;
12
+ const fromYear = min?.year ?? toCalendar(new CalendarDate(DEFAULT_MIN_YEAR, 1, 1), calendar).year;
13
+ const toYear = max?.year ?? toCalendar(new CalendarDate(DEFAULT_MAX_YEAR, 12, 31), calendar).year;
14
+ return { from: fromYear, to: toYear };
15
+ }
16
+ var FUTURE_YEAR_COERCION = 10;
17
+ function normalizeYear(year) {
18
+ if (!year) return;
19
+ if (year.length === 3) return year.padEnd(4, "0");
20
+ if (year.length === 2) {
21
+ const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
22
+ const currentCentury = Math.floor(currentYear / 100) * 100;
23
+ const twoDigitYear = parseInt(year.slice(-2), 10);
24
+ const fullYear = currentCentury + twoDigitYear;
25
+ return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
26
+ }
27
+ return year;
28
+ }
29
+ function getDecadeRange(year, opts) {
30
+ const chunkSize = opts?.strict ? 10 : 12;
31
+ const computedYear = year - year % 10;
32
+ const years = [];
33
+ for (let i = 0; i < chunkSize; i += 1) {
34
+ const value = computedYear + i;
35
+ years.push(value);
36
+ }
37
+ return years;
38
+ }
39
+ export {
40
+ getDecadeRange,
41
+ getDefaultYearRange,
42
+ getYearsRange,
43
+ normalizeYear
44
+ };
@@ -0,0 +1,13 @@
1
+ import * as _internationalized_date from '@internationalized/date';
2
+ import { DateDuration } from '@internationalized/date';
3
+ import { DateValue } from './types.mjs';
4
+
5
+ declare function getUnitDuration(duration: DateDuration): {
6
+ years?: number;
7
+ months?: number;
8
+ weeks?: number;
9
+ days?: number;
10
+ };
11
+ declare function getEndDate(startDate: DateValue, duration: DateDuration): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
12
+
13
+ export { getEndDate, getUnitDuration };
@@ -0,0 +1,13 @@
1
+ import * as _internationalized_date from '@internationalized/date';
2
+ import { DateDuration } from '@internationalized/date';
3
+ import { DateValue } from './types.js';
4
+
5
+ declare function getUnitDuration(duration: DateDuration): {
6
+ years?: number;
7
+ months?: number;
8
+ weeks?: number;
9
+ days?: number;
10
+ };
11
+ declare function getEndDate(startDate: DateValue, duration: DateDuration): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
12
+
13
+ export { getEndDate, getUnitDuration };
@@ -0,0 +1,42 @@
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/duration.ts
21
+ var duration_exports = {};
22
+ __export(duration_exports, {
23
+ getEndDate: () => getEndDate,
24
+ getUnitDuration: () => getUnitDuration
25
+ });
26
+ module.exports = __toCommonJS(duration_exports);
27
+ function getUnitDuration(duration) {
28
+ let clone = { ...duration };
29
+ for (let key in clone) clone[key] = 1;
30
+ return clone;
31
+ }
32
+ function getEndDate(startDate, duration) {
33
+ let clone = { ...duration };
34
+ if (clone.days) clone.days--;
35
+ else clone.days = -1;
36
+ return startDate.add(clone);
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ getEndDate,
41
+ getUnitDuration
42
+ });
@@ -0,0 +1,16 @@
1
+ // src/duration.ts
2
+ function getUnitDuration(duration) {
3
+ let clone = { ...duration };
4
+ for (let key in clone) clone[key] = 1;
5
+ return clone;
6
+ }
7
+ function getEndDate(startDate, duration) {
8
+ let clone = { ...duration };
9
+ if (clone.days) clone.days--;
10
+ else clone.days = -1;
11
+ return startDate.add(clone);
12
+ }
13
+ export {
14
+ getEndDate,
15
+ getUnitDuration
16
+ };
@@ -0,0 +1,8 @@
1
+ import { DateFormatter } from '@internationalized/date';
2
+ import { DateValue } from './types.mjs';
3
+
4
+ declare function formatRange(startDate: DateValue, endDate: DateValue, formatter: DateFormatter, toString: (start: string, end: string) => string, timeZone: string): string;
5
+ declare function formatSelectedDate(startDate: DateValue | null | undefined, endDate: DateValue | null, locale: string, timeZone: string): string;
6
+ declare function formatVisibleRange(startDate: DateValue, endDate: DateValue | null, locale: string, timeZone: string): string;
7
+
8
+ export { formatRange, formatSelectedDate, formatVisibleRange };
@@ -0,0 +1,8 @@
1
+ import { DateFormatter } from '@internationalized/date';
2
+ import { DateValue } from './types.js';
3
+
4
+ declare function formatRange(startDate: DateValue, endDate: DateValue, formatter: DateFormatter, toString: (start: string, end: string) => string, timeZone: string): string;
5
+ declare function formatSelectedDate(startDate: DateValue | null | undefined, endDate: DateValue | null, locale: string, timeZone: string): string;
6
+ declare function formatVisibleRange(startDate: DateValue, endDate: DateValue | null, locale: string, timeZone: string): string;
7
+
8
+ export { formatRange, formatSelectedDate, formatVisibleRange };
package/dist/format.js ADDED
@@ -0,0 +1,83 @@
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.ts
21
+ var format_exports = {};
22
+ __export(format_exports, {
23
+ formatRange: () => formatRange,
24
+ formatSelectedDate: () => formatSelectedDate,
25
+ formatVisibleRange: () => formatVisibleRange
26
+ });
27
+ module.exports = __toCommonJS(format_exports);
28
+ var import_date = require("@internationalized/date");
29
+ var import_formatter = require("./formatter.cjs");
30
+ function formatRange(startDate, endDate, formatter, toString, timeZone) {
31
+ let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
32
+ let separatorIndex = -1;
33
+ for (let i = 0; i < parts.length; i++) {
34
+ let part = parts[i];
35
+ if (part.source === "shared" && part.type === "literal") {
36
+ separatorIndex = i;
37
+ } else if (part.source === "endRange") {
38
+ break;
39
+ }
40
+ }
41
+ let start = "";
42
+ let end = "";
43
+ for (let i = 0; i < parts.length; i++) {
44
+ if (i < separatorIndex) {
45
+ start += parts[i].value;
46
+ } else if (i > separatorIndex) {
47
+ end += parts[i].value;
48
+ }
49
+ }
50
+ return toString(start, end);
51
+ }
52
+ function formatSelectedDate(startDate, endDate, locale, timeZone) {
53
+ if (!startDate) return "";
54
+ let start = startDate;
55
+ let end = endDate ?? startDate;
56
+ let formatter = (0, import_formatter.getDayFormatter)(locale, timeZone);
57
+ if ((0, import_date.isSameDay)(start, end)) {
58
+ return formatter.format(start.toDate(timeZone));
59
+ }
60
+ return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
61
+ }
62
+ function formatVisibleRange(startDate, endDate, locale, timeZone) {
63
+ const start = startDate;
64
+ const end = endDate ?? startDate;
65
+ const dayFormatter = (0, import_formatter.getDayFormatter)(locale, timeZone);
66
+ if (!(0, import_date.isSameDay)(start, (0, import_date.startOfMonth)(start))) {
67
+ return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
68
+ }
69
+ const monthFormatter = (0, import_formatter.getMonthFormatter)(locale, timeZone);
70
+ if ((0, import_date.isSameDay)(end, (0, import_date.endOfMonth)(start))) {
71
+ return monthFormatter.format(start.toDate(timeZone));
72
+ }
73
+ if ((0, import_date.isSameDay)(end, (0, import_date.endOfMonth)(end))) {
74
+ return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
75
+ }
76
+ return "";
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ formatRange,
81
+ formatSelectedDate,
82
+ formatVisibleRange
83
+ });
@@ -0,0 +1,56 @@
1
+ // src/format.ts
2
+ import { endOfMonth, isSameDay, startOfMonth } from "@internationalized/date";
3
+ import { getDayFormatter, getMonthFormatter } from "./formatter.mjs";
4
+ function formatRange(startDate, endDate, formatter, toString, timeZone) {
5
+ let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
6
+ let separatorIndex = -1;
7
+ for (let i = 0; i < parts.length; i++) {
8
+ let part = parts[i];
9
+ if (part.source === "shared" && part.type === "literal") {
10
+ separatorIndex = i;
11
+ } else if (part.source === "endRange") {
12
+ break;
13
+ }
14
+ }
15
+ let start = "";
16
+ let end = "";
17
+ for (let i = 0; i < parts.length; i++) {
18
+ if (i < separatorIndex) {
19
+ start += parts[i].value;
20
+ } else if (i > separatorIndex) {
21
+ end += parts[i].value;
22
+ }
23
+ }
24
+ return toString(start, end);
25
+ }
26
+ function formatSelectedDate(startDate, endDate, locale, timeZone) {
27
+ if (!startDate) return "";
28
+ let start = startDate;
29
+ let end = endDate ?? startDate;
30
+ let formatter = getDayFormatter(locale, timeZone);
31
+ if (isSameDay(start, end)) {
32
+ return formatter.format(start.toDate(timeZone));
33
+ }
34
+ return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
35
+ }
36
+ function formatVisibleRange(startDate, endDate, locale, timeZone) {
37
+ const start = startDate;
38
+ const end = endDate ?? startDate;
39
+ const dayFormatter = getDayFormatter(locale, timeZone);
40
+ if (!isSameDay(start, startOfMonth(start))) {
41
+ return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
42
+ }
43
+ const monthFormatter = getMonthFormatter(locale, timeZone);
44
+ if (isSameDay(end, endOfMonth(start))) {
45
+ return monthFormatter.format(start.toDate(timeZone));
46
+ }
47
+ if (isSameDay(end, endOfMonth(end))) {
48
+ return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
49
+ }
50
+ return "";
51
+ }
52
+ export {
53
+ formatRange,
54
+ formatSelectedDate,
55
+ formatVisibleRange
56
+ };
@@ -0,0 +1,6 @@
1
+ import { DateValue, DateFormatter } from '@internationalized/date';
2
+
3
+ declare function getDayFormatter(locale: string, timeZone: string, referenceDate?: DateValue): DateFormatter;
4
+ declare function getMonthFormatter(locale: string, timeZone: string, referenceDate?: DateValue): DateFormatter;
5
+
6
+ export { getDayFormatter, getMonthFormatter };
@@ -0,0 +1,6 @@
1
+ import { DateValue, DateFormatter } from '@internationalized/date';
2
+
3
+ declare function getDayFormatter(locale: string, timeZone: string, referenceDate?: DateValue): DateFormatter;
4
+ declare function getMonthFormatter(locale: string, timeZone: string, referenceDate?: DateValue): DateFormatter;
5
+
6
+ export { getDayFormatter, getMonthFormatter };
@@ -0,0 +1,55 @@
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/formatter.ts
21
+ var formatter_exports = {};
22
+ __export(formatter_exports, {
23
+ getDayFormatter: () => getDayFormatter,
24
+ getMonthFormatter: () => getMonthFormatter
25
+ });
26
+ module.exports = __toCommonJS(formatter_exports);
27
+ var import_date = require("@internationalized/date");
28
+ var import_get_era_format = require("./get-era-format.cjs");
29
+ function getDayFormatter(locale, timeZone, referenceDate) {
30
+ const date = referenceDate ?? (0, import_date.toCalendarDateTime)((0, import_date.today)(timeZone));
31
+ return new import_date.DateFormatter(locale, {
32
+ weekday: "long",
33
+ month: "long",
34
+ year: "numeric",
35
+ day: "numeric",
36
+ era: (0, import_get_era_format.getEraFormat)(date),
37
+ calendar: date.calendar.identifier,
38
+ timeZone
39
+ });
40
+ }
41
+ function getMonthFormatter(locale, timeZone, referenceDate) {
42
+ const date = referenceDate ?? (0, import_date.today)(timeZone);
43
+ return new import_date.DateFormatter(locale, {
44
+ month: "long",
45
+ year: "numeric",
46
+ era: (0, import_get_era_format.getEraFormat)(date),
47
+ calendar: date.calendar.identifier,
48
+ timeZone
49
+ });
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ getDayFormatter,
54
+ getMonthFormatter
55
+ });
@@ -0,0 +1,29 @@
1
+ // src/formatter.ts
2
+ import { DateFormatter, toCalendarDateTime, today } from "@internationalized/date";
3
+ import { getEraFormat } from "./get-era-format.mjs";
4
+ function getDayFormatter(locale, timeZone, referenceDate) {
5
+ const date = referenceDate ?? toCalendarDateTime(today(timeZone));
6
+ return new DateFormatter(locale, {
7
+ weekday: "long",
8
+ month: "long",
9
+ year: "numeric",
10
+ day: "numeric",
11
+ era: getEraFormat(date),
12
+ calendar: date.calendar.identifier,
13
+ timeZone
14
+ });
15
+ }
16
+ function getMonthFormatter(locale, timeZone, referenceDate) {
17
+ const date = referenceDate ?? today(timeZone);
18
+ return new DateFormatter(locale, {
19
+ month: "long",
20
+ year: "numeric",
21
+ era: getEraFormat(date),
22
+ calendar: date.calendar.identifier,
23
+ timeZone
24
+ });
25
+ }
26
+ export {
27
+ getDayFormatter,
28
+ getMonthFormatter
29
+ };
@@ -0,0 +1,6 @@
1
+ import { DateValue } from './types.mjs';
2
+ import '@internationalized/date';
3
+
4
+ declare function getEraFormat(date: DateValue | undefined): "short" | undefined;
5
+
6
+ export { getEraFormat };
@@ -0,0 +1,6 @@
1
+ import { DateValue } from './types.js';
2
+ import '@internationalized/date';
3
+
4
+ declare function getEraFormat(date: DateValue | undefined): "short" | undefined;
5
+
6
+ export { getEraFormat };
@@ -0,0 +1,37 @@
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/get-era-format.ts
21
+ var get_era_format_exports = {};
22
+ __export(get_era_format_exports, {
23
+ getEraFormat: () => getEraFormat
24
+ });
25
+ module.exports = __toCommonJS(get_era_format_exports);
26
+ function getEraFormat(date) {
27
+ if (!date) return void 0;
28
+ const id = date.calendar.identifier;
29
+ if (id === "gregory" || id === "iso8601") {
30
+ return date.era === "BC" ? "short" : void 0;
31
+ }
32
+ return "short";
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ getEraFormat
37
+ });
@@ -0,0 +1,12 @@
1
+ // src/get-era-format.ts
2
+ function getEraFormat(date) {
3
+ if (!date) return void 0;
4
+ const id = date.calendar.identifier;
5
+ if (id === "gregory" || id === "iso8601") {
6
+ return date.era === "BC" ? "short" : void 0;
7
+ }
8
+ return "short";
9
+ }
10
+ export {
11
+ getEraFormat
12
+ };