@zag-js/date-utils 1.34.0 → 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,8 @@
1
+ import * as _internationalized_date from '@internationalized/date';
2
+ import { DateDuration } from '@internationalized/date';
3
+ import { DateValue, DateAlignment } from './types.mjs';
4
+
5
+ declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
6
+ declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
7
+
8
+ export { alignDate, alignStartDate };
@@ -0,0 +1,8 @@
1
+ import * as _internationalized_date from '@internationalized/date';
2
+ import { DateDuration } from '@internationalized/date';
3
+ import { DateValue, DateAlignment } from './types.js';
4
+
5
+ declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
6
+ declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
7
+
8
+ export { alignDate, alignStartDate };
package/dist/align.js ADDED
@@ -0,0 +1,52 @@
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/align.ts
21
+ var align_exports = {};
22
+ __export(align_exports, {
23
+ alignDate: () => alignDate,
24
+ alignStartDate: () => alignStartDate
25
+ });
26
+ module.exports = __toCommonJS(align_exports);
27
+ var import_constrain = require("./constrain.cjs");
28
+ function alignDate(date, alignment, duration, locale, min, max) {
29
+ switch (alignment) {
30
+ case "start":
31
+ return (0, import_constrain.alignStart)(date, duration, locale, min, max);
32
+ case "end":
33
+ return (0, import_constrain.alignEnd)(date, duration, locale, min, max);
34
+ case "center":
35
+ default:
36
+ return (0, import_constrain.alignCenter)(date, duration, locale, min, max);
37
+ }
38
+ }
39
+ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
40
+ if (date.compare(startDate) < 0) {
41
+ return (0, import_constrain.alignEnd)(date, duration, locale, min, max);
42
+ }
43
+ if (date.compare(endDate) > 0) {
44
+ return (0, import_constrain.alignStart)(date, duration, locale, min, max);
45
+ }
46
+ return startDate;
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ alignDate,
51
+ alignStartDate
52
+ });
package/dist/align.mjs ADDED
@@ -0,0 +1,26 @@
1
+ // src/align.ts
2
+ import { alignCenter, alignEnd, alignStart } from "./constrain.mjs";
3
+ function alignDate(date, alignment, duration, locale, min, max) {
4
+ switch (alignment) {
5
+ case "start":
6
+ return alignStart(date, duration, locale, min, max);
7
+ case "end":
8
+ return alignEnd(date, duration, locale, min, max);
9
+ case "center":
10
+ default:
11
+ return alignCenter(date, duration, locale, min, max);
12
+ }
13
+ }
14
+ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
15
+ if (date.compare(startDate) < 0) {
16
+ return alignEnd(date, duration, locale, min, max);
17
+ }
18
+ if (date.compare(endDate) > 0) {
19
+ return alignStart(date, duration, locale, min, max);
20
+ }
21
+ return startDate;
22
+ }
23
+ export {
24
+ alignDate,
25
+ alignStartDate
26
+ };
@@ -0,0 +1,10 @@
1
+ import { DateValue, DateAvailableFn } from './types.mjs';
2
+ import '@internationalized/date';
3
+
4
+ declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
5
+ declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
+ declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
7
+ declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
+ declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
9
+
10
+ export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
@@ -0,0 +1,10 @@
1
+ import { DateValue, DateAvailableFn } from './types.js';
2
+ import '@internationalized/date';
3
+
4
+ declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
5
+ declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
+ declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
7
+ declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
+ declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
9
+
10
+ export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
@@ -0,0 +1,58 @@
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/assertion.ts
21
+ var assertion_exports = {};
22
+ __export(assertion_exports, {
23
+ isDateEqual: () => isDateEqual,
24
+ isDateOutsideRange: () => isDateOutsideRange,
25
+ isDateUnavailable: () => isDateUnavailable,
26
+ isNextRangeInvalid: () => isNextRangeInvalid,
27
+ isPreviousRangeInvalid: () => isPreviousRangeInvalid
28
+ });
29
+ module.exports = __toCommonJS(assertion_exports);
30
+ var import_date = require("@internationalized/date");
31
+ function isDateEqual(dateA, dateB) {
32
+ if (dateA == null || dateB == null) return dateA === dateB;
33
+ return (0, import_date.isSameDay)(dateA, dateB);
34
+ }
35
+ function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
36
+ if (!date) return false;
37
+ if (isUnavailable?.(date, locale)) return true;
38
+ return isDateOutsideRange(date, minValue, maxValue);
39
+ }
40
+ function isDateOutsideRange(date, startDate, endDate) {
41
+ return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
42
+ }
43
+ function isPreviousRangeInvalid(startDate, minValue, maxValue) {
44
+ const prevDate = startDate.subtract({ days: 1 });
45
+ return (0, import_date.isSameDay)(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
46
+ }
47
+ function isNextRangeInvalid(endDate, minValue, maxValue) {
48
+ const nextDate = endDate.add({ days: 1 });
49
+ return (0, import_date.isSameDay)(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ isDateEqual,
54
+ isDateOutsideRange,
55
+ isDateUnavailable,
56
+ isNextRangeInvalid,
57
+ isPreviousRangeInvalid
58
+ });
@@ -0,0 +1,29 @@
1
+ // src/assertion.ts
2
+ import { isSameDay } from "@internationalized/date";
3
+ function isDateEqual(dateA, dateB) {
4
+ if (dateA == null || dateB == null) return dateA === dateB;
5
+ return isSameDay(dateA, dateB);
6
+ }
7
+ function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
8
+ if (!date) return false;
9
+ if (isUnavailable?.(date, locale)) return true;
10
+ return isDateOutsideRange(date, minValue, maxValue);
11
+ }
12
+ function isDateOutsideRange(date, startDate, endDate) {
13
+ return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
14
+ }
15
+ function isPreviousRangeInvalid(startDate, minValue, maxValue) {
16
+ const prevDate = startDate.subtract({ days: 1 });
17
+ return isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
18
+ }
19
+ function isNextRangeInvalid(endDate, minValue, maxValue) {
20
+ const nextDate = endDate.add({ days: 1 });
21
+ return isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
22
+ }
23
+ export {
24
+ isDateEqual,
25
+ isDateOutsideRange,
26
+ isDateUnavailable,
27
+ isNextRangeInvalid,
28
+ isPreviousRangeInvalid
29
+ };
@@ -0,0 +1,9 @@
1
+ import { DateValue, DateDuration } from '@internationalized/date';
2
+
3
+ declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
4
+ declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
5
+ declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
6
+ declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
7
+ declare function constrainValue<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
8
+
9
+ export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue };
@@ -0,0 +1,9 @@
1
+ import { DateValue, DateDuration } from '@internationalized/date';
2
+
3
+ declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
4
+ declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
5
+ declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
6
+ declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
7
+ declare function constrainValue<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
8
+
9
+ export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue };
@@ -0,0 +1,109 @@
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/constrain.ts
21
+ var constrain_exports = {};
22
+ __export(constrain_exports, {
23
+ alignCenter: () => alignCenter,
24
+ alignEnd: () => alignEnd,
25
+ alignStart: () => alignStart,
26
+ constrainStart: () => constrainStart,
27
+ constrainValue: () => constrainValue
28
+ });
29
+ module.exports = __toCommonJS(constrain_exports);
30
+ var import_date = require("@internationalized/date");
31
+ function alignCenter(date, duration, locale, min, max) {
32
+ const halfDuration = {};
33
+ for (let prop in duration) {
34
+ const key = prop;
35
+ const value = duration[key];
36
+ if (value == null) continue;
37
+ halfDuration[key] = Math.floor(value / 2);
38
+ if (halfDuration[key] > 0 && value % 2 === 0) {
39
+ halfDuration[key]--;
40
+ }
41
+ }
42
+ const aligned = alignStart(date, duration, locale).subtract(halfDuration);
43
+ return constrainStart(date, aligned, duration, locale, min, max);
44
+ }
45
+ function alignStart(date, duration, locale, min, max) {
46
+ let aligned = date;
47
+ if (duration.years) {
48
+ aligned = (0, import_date.startOfYear)(date);
49
+ } else if (duration.months) {
50
+ aligned = (0, import_date.startOfMonth)(date);
51
+ } else if (duration.weeks) {
52
+ aligned = (0, import_date.startOfWeek)(date, locale);
53
+ }
54
+ return constrainStart(date, aligned, duration, locale, min, max);
55
+ }
56
+ function alignEnd(date, duration, locale, min, max) {
57
+ let d = { ...duration };
58
+ if (d.days) {
59
+ d.days--;
60
+ } else if (d.weeks) {
61
+ d.weeks--;
62
+ } else if (d.months) {
63
+ d.months--;
64
+ } else if (d.years) {
65
+ d.years--;
66
+ }
67
+ let aligned = alignStart(date, duration, locale).subtract(d);
68
+ return constrainStart(date, aligned, duration, locale, min, max);
69
+ }
70
+ function constrainStart(date, aligned, duration, locale, min, max) {
71
+ if (min && date.compare(min) >= 0) {
72
+ aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
73
+ }
74
+ if (max && date.compare(max) <= 0) {
75
+ aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
76
+ }
77
+ return aligned;
78
+ }
79
+ function constrainValue(date, minValue, maxValue) {
80
+ const dateOnly = (0, import_date.toCalendarDate)(date);
81
+ const minOnly = minValue ? (0, import_date.toCalendarDate)(minValue) : void 0;
82
+ const maxOnly = maxValue ? (0, import_date.toCalendarDate)(maxValue) : void 0;
83
+ let constrainedDateOnly = dateOnly;
84
+ if (minOnly) {
85
+ constrainedDateOnly = (0, import_date.maxDate)(constrainedDateOnly, minOnly);
86
+ }
87
+ if (maxOnly) {
88
+ constrainedDateOnly = (0, import_date.minDate)(constrainedDateOnly, maxOnly);
89
+ }
90
+ if (constrainedDateOnly.compare(dateOnly) === 0) {
91
+ return date;
92
+ }
93
+ if ("hour" in date) {
94
+ return date.set({
95
+ year: constrainedDateOnly.year,
96
+ month: constrainedDateOnly.month,
97
+ day: constrainedDateOnly.day
98
+ });
99
+ }
100
+ return constrainedDateOnly;
101
+ }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ alignCenter,
105
+ alignEnd,
106
+ alignStart,
107
+ constrainStart,
108
+ constrainValue
109
+ });
@@ -0,0 +1,87 @@
1
+ // src/constrain.ts
2
+ import {
3
+ maxDate,
4
+ minDate,
5
+ startOfMonth,
6
+ startOfWeek,
7
+ startOfYear,
8
+ toCalendarDate
9
+ } from "@internationalized/date";
10
+ function alignCenter(date, duration, locale, min, max) {
11
+ const halfDuration = {};
12
+ for (let prop in duration) {
13
+ const key = prop;
14
+ const value = duration[key];
15
+ if (value == null) continue;
16
+ halfDuration[key] = Math.floor(value / 2);
17
+ if (halfDuration[key] > 0 && value % 2 === 0) {
18
+ halfDuration[key]--;
19
+ }
20
+ }
21
+ const aligned = alignStart(date, duration, locale).subtract(halfDuration);
22
+ return constrainStart(date, aligned, duration, locale, min, max);
23
+ }
24
+ function alignStart(date, duration, locale, min, max) {
25
+ let aligned = date;
26
+ if (duration.years) {
27
+ aligned = startOfYear(date);
28
+ } else if (duration.months) {
29
+ aligned = startOfMonth(date);
30
+ } else if (duration.weeks) {
31
+ aligned = startOfWeek(date, locale);
32
+ }
33
+ return constrainStart(date, aligned, duration, locale, min, max);
34
+ }
35
+ function alignEnd(date, duration, locale, min, max) {
36
+ let d = { ...duration };
37
+ if (d.days) {
38
+ d.days--;
39
+ } else if (d.weeks) {
40
+ d.weeks--;
41
+ } else if (d.months) {
42
+ d.months--;
43
+ } else if (d.years) {
44
+ d.years--;
45
+ }
46
+ let aligned = alignStart(date, duration, locale).subtract(d);
47
+ return constrainStart(date, aligned, duration, locale, min, max);
48
+ }
49
+ function constrainStart(date, aligned, duration, locale, min, max) {
50
+ if (min && date.compare(min) >= 0) {
51
+ aligned = maxDate(aligned, alignStart(toCalendarDate(min), duration, locale));
52
+ }
53
+ if (max && date.compare(max) <= 0) {
54
+ aligned = minDate(aligned, alignEnd(toCalendarDate(max), duration, locale));
55
+ }
56
+ return aligned;
57
+ }
58
+ function constrainValue(date, minValue, maxValue) {
59
+ const dateOnly = toCalendarDate(date);
60
+ const minOnly = minValue ? toCalendarDate(minValue) : void 0;
61
+ const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
62
+ let constrainedDateOnly = dateOnly;
63
+ if (minOnly) {
64
+ constrainedDateOnly = maxDate(constrainedDateOnly, minOnly);
65
+ }
66
+ if (maxOnly) {
67
+ constrainedDateOnly = minDate(constrainedDateOnly, maxOnly);
68
+ }
69
+ if (constrainedDateOnly.compare(dateOnly) === 0) {
70
+ return date;
71
+ }
72
+ if ("hour" in date) {
73
+ return date.set({
74
+ year: constrainedDateOnly.year,
75
+ month: constrainedDateOnly.month,
76
+ day: constrainedDateOnly.day
77
+ });
78
+ }
79
+ return constrainedDateOnly;
80
+ }
81
+ export {
82
+ alignCenter,
83
+ alignEnd,
84
+ alignStart,
85
+ constrainStart,
86
+ constrainValue
87
+ };
@@ -0,0 +1,23 @@
1
+ import * as _internationalized_date from '@internationalized/date';
2
+ import { DateValue } from '@internationalized/date';
3
+
4
+ declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
5
+ declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
6
+ declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
7
+ declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
8
+ declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
9
+ value: T;
10
+ short: string;
11
+ long: string;
12
+ narrow: string;
13
+ };
14
+ declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
15
+ value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
16
+ short: string;
17
+ long: string;
18
+ narrow: string;
19
+ }[];
20
+ declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
21
+ declare function getWeekOfYear(date: DateValue, locale: string): number;
22
+
23
+ export { getDaysInWeek, getEndOfWeek, getMonthDays, getMonthNames, getStartOfWeek, getWeekDays, getWeekOfYear, getWeekdayFormats };
@@ -0,0 +1,23 @@
1
+ import * as _internationalized_date from '@internationalized/date';
2
+ import { DateValue } from '@internationalized/date';
3
+
4
+ declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
5
+ declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
6
+ declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
7
+ declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
8
+ declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
9
+ value: T;
10
+ short: string;
11
+ long: string;
12
+ narrow: string;
13
+ };
14
+ declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
15
+ value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
16
+ short: string;
17
+ long: string;
18
+ narrow: string;
19
+ }[];
20
+ declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
21
+ declare function getWeekOfYear(date: DateValue, locale: string): number;
22
+
23
+ export { getDaysInWeek, getEndOfWeek, getMonthDays, getMonthNames, getStartOfWeek, getWeekDays, getWeekOfYear, getWeekdayFormats };
@@ -0,0 +1,131 @@
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-month.ts
21
+ var date_month_exports = {};
22
+ __export(date_month_exports, {
23
+ getDaysInWeek: () => getDaysInWeek,
24
+ getEndOfWeek: () => getEndOfWeek,
25
+ getMonthDays: () => getMonthDays,
26
+ getMonthNames: () => getMonthNames,
27
+ getStartOfWeek: () => getStartOfWeek,
28
+ getWeekDays: () => getWeekDays,
29
+ getWeekOfYear: () => getWeekOfYear,
30
+ getWeekdayFormats: () => getWeekdayFormats
31
+ });
32
+ module.exports = __toCommonJS(date_month_exports);
33
+ var import_date = require("@internationalized/date");
34
+ var daysOfTheWeek = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
35
+ function normalizeFirstDayOfWeek(firstDayOfWeek) {
36
+ return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
37
+ }
38
+ function getStartOfWeek(date, locale, firstDayOfWeek) {
39
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
40
+ return (0, import_date.startOfWeek)(date, locale, firstDay);
41
+ }
42
+ function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
43
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
44
+ return (0, import_date.endOfWeek)(date, locale, firstDay);
45
+ }
46
+ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
47
+ const weekDate = from.add({ weeks: weekIndex });
48
+ const dates = [];
49
+ let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
50
+ while (dates.length < 7) {
51
+ dates.push(date);
52
+ let nextDate = date.add({ days: 1 });
53
+ if ((0, import_date.isSameDay)(date, nextDate)) break;
54
+ date = nextDate;
55
+ }
56
+ return dates;
57
+ }
58
+ function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
59
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
60
+ const monthWeeks = numOfWeeks ?? (0, import_date.getWeeksInMonth)(from, locale, firstDay);
61
+ const weeks = [...new Array(monthWeeks).keys()];
62
+ return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
63
+ }
64
+ function getWeekdayFormats(locale, timeZone) {
65
+ const longFormat = new import_date.DateFormatter(locale, { weekday: "long", timeZone });
66
+ const shortFormat = new import_date.DateFormatter(locale, { weekday: "short", timeZone });
67
+ const narrowFormat = new import_date.DateFormatter(locale, { weekday: "narrow", timeZone });
68
+ return (value) => {
69
+ const date = value instanceof Date ? value : value.toDate(timeZone);
70
+ return {
71
+ value,
72
+ short: shortFormat.format(date),
73
+ long: longFormat.format(date),
74
+ narrow: narrowFormat.format(date)
75
+ };
76
+ };
77
+ }
78
+ function getWeekDays(date, startOfWeekProp, timeZone, locale) {
79
+ const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
80
+ const weeks = [...new Array(7).keys()];
81
+ const format = getWeekdayFormats(locale, timeZone);
82
+ return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
83
+ }
84
+ function getMonthNames(locale, format = "long", referenceDate) {
85
+ if (!referenceDate || referenceDate.calendar.identifier === "gregory" || referenceDate.calendar.identifier === "iso8601") {
86
+ const date = new Date(2021, 0, 1);
87
+ const monthNames2 = [];
88
+ for (let i = 0; i < 12; i++) {
89
+ monthNames2.push(date.toLocaleString(locale, { month: format }));
90
+ date.setMonth(date.getMonth() + 1);
91
+ }
92
+ return monthNames2;
93
+ }
94
+ const monthCount = referenceDate.calendar.getMonthsInYear(referenceDate);
95
+ const formatter = new import_date.DateFormatter(locale, {
96
+ month: format,
97
+ calendar: referenceDate.calendar.identifier
98
+ });
99
+ const monthNames = [];
100
+ for (let month = 1; month <= monthCount; month++) {
101
+ const d = referenceDate.set({ month });
102
+ monthNames.push(formatter.format(d.toDate("UTC")));
103
+ }
104
+ return monthNames;
105
+ }
106
+ function getWeekOfYear(date, locale) {
107
+ const mondayOfWeek = (0, import_date.startOfWeek)(date, locale, "mon");
108
+ const year = mondayOfWeek.year;
109
+ const jan4 = mondayOfWeek.set({ month: 1, day: 4 });
110
+ const week1Monday = (0, import_date.startOfWeek)(jan4, locale, "mon");
111
+ const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
112
+ const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
113
+ if (julianMonday >= julianWeek1) {
114
+ return 1 + Math.floor((julianMonday - julianWeek1) / 7);
115
+ }
116
+ const prevJan4 = mondayOfWeek.set({ year: year - 1, month: 1, day: 4 });
117
+ const prevWeek1Monday = (0, import_date.startOfWeek)(prevJan4, locale, "mon");
118
+ const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
119
+ return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ getDaysInWeek,
124
+ getEndOfWeek,
125
+ getMonthDays,
126
+ getMonthNames,
127
+ getStartOfWeek,
128
+ getWeekDays,
129
+ getWeekOfYear,
130
+ getWeekdayFormats
131
+ });