@zag-js/date-utils 0.10.2 → 0.10.3

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 (104) hide show
  1. package/dist/align.d.ts +4 -7
  2. package/dist/align.js +11 -83
  3. package/dist/align.mjs +24 -9
  4. package/dist/assertion.d.ts +10 -13
  5. package/dist/assertion.js +19 -48
  6. package/dist/assertion.mjs +36 -20
  7. package/dist/constrain.d.ts +6 -9
  8. package/dist/constrain.js +26 -52
  9. package/dist/constrain.mjs +58 -14
  10. package/dist/duration.d.ts +3 -7
  11. package/dist/duration.js +6 -30
  12. package/dist/duration.mjs +18 -8
  13. package/dist/format-date.d.ts +2 -5
  14. package/dist/format-date.js +32 -54
  15. package/dist/format-date.mjs +53 -6
  16. package/dist/format-range.d.ts +2 -5
  17. package/dist/format-range.js +5 -28
  18. package/dist/format-range.mjs +24 -6
  19. package/dist/format-selected-date.d.ts +2 -5
  20. package/dist/format-selected-date.js +10 -77
  21. package/dist/format-selected-date.mjs +15 -9
  22. package/dist/format-visible-range.d.ts +2 -5
  23. package/dist/format-visible-range.js +12 -68
  24. package/dist/format-visible-range.mjs +22 -9
  25. package/dist/get-day-formatter.d.ts +2 -5
  26. package/dist/get-day-formatter.js +9 -37
  27. package/dist/get-day-formatter.mjs +16 -7
  28. package/dist/get-decade-range.d.ts +1 -3
  29. package/dist/get-decade-range.js +5 -28
  30. package/dist/get-decade-range.mjs +11 -6
  31. package/dist/get-era-format.d.ts +2 -5
  32. package/dist/get-era-format.js +5 -28
  33. package/dist/get-era-format.mjs +5 -6
  34. package/dist/get-month-days.d.ts +3 -6
  35. package/dist/get-month-days.js +13 -45
  36. package/dist/get-month-days.mjs +24 -9
  37. package/dist/get-month-formatter.d.ts +2 -5
  38. package/dist/get-month-formatter.js +10 -38
  39. package/dist/get-month-formatter.mjs +15 -7
  40. package/dist/get-month-names.d.ts +1 -3
  41. package/dist/get-month-names.js +5 -28
  42. package/dist/get-month-names.mjs +11 -6
  43. package/dist/get-start-of-week.d.ts +2 -6
  44. package/dist/get-start-of-week.js +10 -32
  45. package/dist/get-start-of-week.mjs +9 -6
  46. package/dist/get-week-days.d.ts +3 -7
  47. package/dist/get-week-days.js +8 -55
  48. package/dist/get-week-days.mjs +11 -8
  49. package/dist/get-weekday-formats.d.ts +2 -5
  50. package/dist/get-weekday-formats.js +10 -32
  51. package/dist/get-weekday-formats.mjs +18 -6
  52. package/dist/get-year-range.d.ts +2 -4
  53. package/dist/get-year-range.js +5 -28
  54. package/dist/get-year-range.mjs +9 -6
  55. package/dist/index.d.ts +20 -21
  56. package/dist/index.js +74 -740
  57. package/dist/index.mjs +19 -138
  58. package/dist/mutation.d.ts +10 -14
  59. package/dist/mutation.js +17 -59
  60. package/dist/mutation.mjs +40 -21
  61. package/dist/pagination.d.ts +19 -23
  62. package/dist/pagination.js +35 -134
  63. package/dist/pagination.mjs +179 -25
  64. package/dist/parse-date.d.ts +2 -5
  65. package/dist/parse-date.js +13 -35
  66. package/dist/parse-date.mjs +40 -6
  67. package/dist/types.d.ts +8 -11
  68. package/package.json +2 -7
  69. package/src/assertion.ts +1 -1
  70. package/src/constrain.ts +2 -2
  71. package/src/format-date.ts +1 -1
  72. package/src/format-selected-date.ts +1 -1
  73. package/src/format-visible-range.ts +1 -1
  74. package/src/get-month-days.ts +1 -1
  75. package/src/get-start-of-week.ts +1 -1
  76. package/src/get-weekday-formats.ts +1 -1
  77. package/src/mutation.ts +8 -1
  78. package/src/pagination.ts +8 -1
  79. package/dist/chunk-5HGHDJ3L.mjs +0 -14
  80. package/dist/chunk-6FNTXW54.mjs +0 -52
  81. package/dist/chunk-6LXTZHZP.mjs +0 -22
  82. package/dist/chunk-AMZ7CJ5F.mjs +0 -18
  83. package/dist/chunk-BUT5IUNZ.mjs +0 -32
  84. package/dist/chunk-FJKH6IJZ.mjs +0 -21
  85. package/dist/chunk-G4VVKINZ.mjs +0 -14
  86. package/dist/chunk-HKHGJ6WS.mjs +0 -27
  87. package/dist/chunk-HLAN6TUA.mjs +0 -45
  88. package/dist/chunk-KBGJA6NB.mjs +0 -55
  89. package/dist/chunk-KLHRN7WS.mjs +0 -20
  90. package/dist/chunk-KN3YMOSL.mjs +0 -8
  91. package/dist/chunk-KQVWH4YA.mjs +0 -29
  92. package/dist/chunk-LGEGBP3O.mjs +0 -20
  93. package/dist/chunk-MGPXEJO4.mjs +0 -71
  94. package/dist/chunk-NV7UFBMY.mjs +0 -30
  95. package/dist/chunk-POBWDZPE.mjs +0 -200
  96. package/dist/chunk-SI75FOJ2.mjs +0 -11
  97. package/dist/chunk-TTJVXKJY.mjs +0 -12
  98. package/dist/chunk-WQYMLJUJ.mjs +0 -42
  99. package/dist/chunk-ZSLC7OI2.mjs +0 -22
  100. package/dist/get-end-of-week.d.ts +0 -6
  101. package/dist/get-end-of-week.js +0 -42
  102. package/dist/get-end-of-week.mjs +0 -11
  103. package/dist/types.js +0 -18
  104. package/dist/types.mjs +0 -0
package/dist/align.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- import { DateValue, DateDuration } from '@internationalized/date';
2
- import { DateAlignment } from './types.js';
3
-
4
- declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
5
- declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
6
-
7
- export { alignDate, alignStartDate };
1
+ import type { DateDuration, DateValue } from "@internationalized/date";
2
+ import type { DateAlignment } from "./types";
3
+ export declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
4
+ export declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
package/dist/align.js CHANGED
@@ -1,101 +1,29 @@
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);
1
+ 'use strict';
19
2
 
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);
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
27
4
 
28
- // src/constrain.ts
29
- var import_date = require("@internationalized/date");
30
- function alignCenter(date, duration, locale, min, max) {
31
- let halfDuration = {};
32
- for (let key in duration) {
33
- halfDuration[key] = Math.floor(duration[key] / 2);
34
- if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
35
- halfDuration[key]--;
36
- }
37
- }
38
- let aligned = alignStart(date, duration, locale).subtract(halfDuration);
39
- return constrainStart(date, aligned, duration, locale, min, max);
40
- }
41
- function alignStart(date, duration, locale, min, max) {
42
- let aligned = date;
43
- if (duration.years) {
44
- aligned = (0, import_date.startOfYear)(date);
45
- } else if (duration.months) {
46
- aligned = (0, import_date.startOfMonth)(date);
47
- } else if (duration.weeks) {
48
- aligned = (0, import_date.startOfWeek)(date, locale);
49
- }
50
- return constrainStart(date, aligned, duration, locale, min, max);
51
- }
52
- function alignEnd(date, duration, locale, min, max) {
53
- let d = { ...duration };
54
- if (d.days) {
55
- d.days--;
56
- } else if (d.weeks) {
57
- d.weeks--;
58
- } else if (d.months) {
59
- d.months--;
60
- } else if (d.years) {
61
- d.years--;
62
- }
63
- let aligned = alignStart(date, duration, locale).subtract(d);
64
- return constrainStart(date, aligned, duration, locale, min, max);
65
- }
66
- function constrainStart(date, aligned, duration, locale, min, max) {
67
- if (min && date.compare(min) >= 0) {
68
- aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
69
- }
70
- if (max && date.compare(max) <= 0) {
71
- aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
72
- }
73
- return aligned;
74
- }
5
+ const constrain = require('./constrain.js');
75
6
 
76
- // src/align.ts
77
7
  function alignDate(date, alignment, duration, locale, min, max) {
78
8
  switch (alignment) {
79
9
  case "start":
80
- return alignStart(date, duration, locale, min, max);
10
+ return constrain.alignStart(date, duration, locale, min, max);
81
11
  case "end":
82
- return alignEnd(date, duration, locale, min, max);
12
+ return constrain.alignEnd(date, duration, locale, min, max);
83
13
  case "center":
84
14
  default:
85
- return alignCenter(date, duration, locale, min, max);
15
+ return constrain.alignCenter(date, duration, locale, min, max);
86
16
  }
87
17
  }
88
18
  function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
89
19
  if (date.compare(startDate) < 0) {
90
- return alignEnd(date, duration, locale, min, max);
20
+ return constrain.alignEnd(date, duration, locale, min, max);
91
21
  }
92
22
  if (date.compare(endDate) > 0) {
93
- return alignStart(date, duration, locale, min, max);
23
+ return constrain.alignStart(date, duration, locale, min, max);
94
24
  }
95
25
  return startDate;
96
26
  }
97
- // Annotate the CommonJS export names for ESM import in node:
98
- 0 && (module.exports = {
99
- alignDate,
100
- alignStartDate
101
- });
27
+
28
+ exports.alignDate = alignDate;
29
+ exports.alignStartDate = alignStartDate;
package/dist/align.mjs CHANGED
@@ -1,9 +1,24 @@
1
- import {
2
- alignDate,
3
- alignStartDate
4
- } from "./chunk-BUT5IUNZ.mjs";
5
- import "./chunk-MGPXEJO4.mjs";
6
- export {
7
- alignDate,
8
- alignStartDate
9
- };
1
+ import { alignCenter, alignEnd, alignStart } from './constrain.mjs';
2
+
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
+
24
+ export { alignDate, alignStartDate };
@@ -1,13 +1,10 @@
1
- import { DateValue } from '@internationalized/date';
2
- import { DateAvailableFn } from './types.js';
3
-
4
- declare function isTodayDate(date: DateValue, timeZone: string): boolean;
5
- declare function isDateEqual(dateA: DateValue, dateB?: DateValue | null): boolean;
6
- declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
7
- declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
- declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
9
- declare function isDateOutsideVisibleRange(date: DateValue, startDate: DateValue, endDate: DateValue): boolean;
10
- declare function isPreviousVisibleRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
11
- declare function isNextVisibleRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
12
-
13
- export { isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, isTodayDate };
1
+ import { type DateValue } from "@internationalized/date";
2
+ import type { DateAvailableFn } from "./types";
3
+ export declare function isTodayDate(date: DateValue, timeZone: string): boolean;
4
+ export declare function isDateEqual(dateA: DateValue, dateB?: DateValue | null): boolean;
5
+ export declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
+ export declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
7
+ export declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
+ export declare function isDateOutsideVisibleRange(date: DateValue, startDate: DateValue, endDate: DateValue): boolean;
9
+ export declare function isPreviousVisibleRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
10
+ export declare function isNextVisibleRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
package/dist/assertion.js CHANGED
@@ -1,41 +1,14 @@
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);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
19
4
 
20
- // src/assertion.ts
21
- var assertion_exports = {};
22
- __export(assertion_exports, {
23
- isDateDisabled: () => isDateDisabled,
24
- isDateEqual: () => isDateEqual,
25
- isDateInvalid: () => isDateInvalid,
26
- isDateOutsideVisibleRange: () => isDateOutsideVisibleRange,
27
- isDateUnavailable: () => isDateUnavailable,
28
- isNextVisibleRangeInvalid: () => isNextVisibleRangeInvalid,
29
- isPreviousVisibleRangeInvalid: () => isPreviousVisibleRangeInvalid,
30
- isTodayDate: () => isTodayDate
31
- });
32
- module.exports = __toCommonJS(assertion_exports);
33
- var import_date = require("@internationalized/date");
34
- function isTodayDate(date, timeZone) {
35
- return (0, import_date.isToday)(date, timeZone);
5
+ const date = require('@internationalized/date');
6
+
7
+ function isTodayDate(date$1, timeZone) {
8
+ return date.isToday(date$1, timeZone);
36
9
  }
37
10
  function isDateEqual(dateA, dateB) {
38
- return dateB != null && (0, import_date.isSameDay)(dateA, dateB);
11
+ return dateB != null && date.isSameDay(dateA, dateB);
39
12
  }
40
13
  function isDateInvalid(date, minValue, maxValue) {
41
14
  return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
@@ -57,20 +30,18 @@ function isDateOutsideVisibleRange(date, startDate, endDate) {
57
30
  }
58
31
  function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
59
32
  const prevDate = startDate.subtract({ days: 1 });
60
- return (0, import_date.isSameDay)(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
33
+ return date.isSameDay(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
61
34
  }
62
35
  function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
63
36
  const nextDate = endDate.add({ days: 1 });
64
- return (0, import_date.isSameDay)(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
37
+ return date.isSameDay(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
65
38
  }
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {
68
- isDateDisabled,
69
- isDateEqual,
70
- isDateInvalid,
71
- isDateOutsideVisibleRange,
72
- isDateUnavailable,
73
- isNextVisibleRangeInvalid,
74
- isPreviousVisibleRangeInvalid,
75
- isTodayDate
76
- });
39
+
40
+ exports.isDateDisabled = isDateDisabled;
41
+ exports.isDateEqual = isDateEqual;
42
+ exports.isDateInvalid = isDateInvalid;
43
+ exports.isDateOutsideVisibleRange = isDateOutsideVisibleRange;
44
+ exports.isDateUnavailable = isDateUnavailable;
45
+ exports.isNextVisibleRangeInvalid = isNextVisibleRangeInvalid;
46
+ exports.isPreviousVisibleRangeInvalid = isPreviousVisibleRangeInvalid;
47
+ exports.isTodayDate = isTodayDate;
@@ -1,20 +1,36 @@
1
- import {
2
- isDateDisabled,
3
- isDateEqual,
4
- isDateInvalid,
5
- isDateOutsideVisibleRange,
6
- isDateUnavailable,
7
- isNextVisibleRangeInvalid,
8
- isPreviousVisibleRangeInvalid,
9
- isTodayDate
10
- } from "./chunk-HLAN6TUA.mjs";
11
- export {
12
- isDateDisabled,
13
- isDateEqual,
14
- isDateInvalid,
15
- isDateOutsideVisibleRange,
16
- isDateUnavailable,
17
- isNextVisibleRangeInvalid,
18
- isPreviousVisibleRangeInvalid,
19
- isTodayDate
20
- };
1
+ import { isToday, isSameDay } from '@internationalized/date';
2
+
3
+ function isTodayDate(date, timeZone) {
4
+ return isToday(date, timeZone);
5
+ }
6
+ function isDateEqual(dateA, dateB) {
7
+ return dateB != null && isSameDay(dateA, dateB);
8
+ }
9
+ function isDateInvalid(date, minValue, maxValue) {
10
+ return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
11
+ }
12
+ function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
13
+ return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(date, minValue, maxValue);
14
+ }
15
+ function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
16
+ if (!date) {
17
+ return false;
18
+ }
19
+ if (isUnavailable?.(date, locale)) {
20
+ return true;
21
+ }
22
+ return isDateInvalid(date, minValue, maxValue);
23
+ }
24
+ function isDateOutsideVisibleRange(date, startDate, endDate) {
25
+ return date.compare(startDate) < 0 || date.compare(endDate) > 0;
26
+ }
27
+ function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
28
+ const prevDate = startDate.subtract({ days: 1 });
29
+ return isSameDay(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
30
+ }
31
+ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
32
+ const nextDate = endDate.add({ days: 1 });
33
+ return isSameDay(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
34
+ }
35
+
36
+ export { isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, isTodayDate };
@@ -1,9 +1,6 @@
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(date: DateValue, minValue?: DateValue, maxValue?: DateValue): DateValue;
8
-
9
- export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue };
1
+ import { type DateDuration, type DateValue } from "@internationalized/date";
2
+ export declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
3
+ export declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
4
+ export declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
5
+ export declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
6
+ export declare function constrainValue(date: DateValue, minValue?: DateValue, maxValue?: DateValue): DateValue;
package/dist/constrain.js CHANGED
@@ -1,33 +1,9 @@
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);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const date = require('@internationalized/date');
19
6
 
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
7
  function alignCenter(date, duration, locale, min, max) {
32
8
  let halfDuration = {};
33
9
  for (let key in duration) {
@@ -39,16 +15,16 @@ function alignCenter(date, duration, locale, min, max) {
39
15
  let aligned = alignStart(date, duration, locale).subtract(halfDuration);
40
16
  return constrainStart(date, aligned, duration, locale, min, max);
41
17
  }
42
- function alignStart(date, duration, locale, min, max) {
43
- let aligned = date;
18
+ function alignStart(date$1, duration, locale, min, max) {
19
+ let aligned = date$1;
44
20
  if (duration.years) {
45
- aligned = (0, import_date.startOfYear)(date);
21
+ aligned = date.startOfYear(date$1);
46
22
  } else if (duration.months) {
47
- aligned = (0, import_date.startOfMonth)(date);
23
+ aligned = date.startOfMonth(date$1);
48
24
  } else if (duration.weeks) {
49
- aligned = (0, import_date.startOfWeek)(date, locale);
25
+ aligned = date.startOfWeek(date$1, locale);
50
26
  }
51
- return constrainStart(date, aligned, duration, locale, min, max);
27
+ return constrainStart(date$1, aligned, duration, locale, min, max);
52
28
  }
53
29
  function alignEnd(date, duration, locale, min, max) {
54
30
  let d = { ...duration };
@@ -64,29 +40,27 @@ function alignEnd(date, duration, locale, min, max) {
64
40
  let aligned = alignStart(date, duration, locale).subtract(d);
65
41
  return constrainStart(date, aligned, duration, locale, min, max);
66
42
  }
67
- function constrainStart(date, aligned, duration, locale, min, max) {
68
- if (min && date.compare(min) >= 0) {
69
- aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
43
+ function constrainStart(date$1, aligned, duration, locale, min, max) {
44
+ if (min && date$1.compare(min) >= 0) {
45
+ aligned = date.maxDate(aligned, alignStart(date.toCalendarDate(min), duration, locale));
70
46
  }
71
- if (max && date.compare(max) <= 0) {
72
- aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
47
+ if (max && date$1.compare(max) <= 0) {
48
+ aligned = date.minDate(aligned, alignEnd(date.toCalendarDate(max), duration, locale));
73
49
  }
74
50
  return aligned;
75
51
  }
76
- function constrainValue(date, minValue, maxValue) {
52
+ function constrainValue(date$1, minValue, maxValue) {
77
53
  if (minValue) {
78
- date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(minValue));
54
+ date$1 = date.maxDate(date$1, date.toCalendarDate(minValue));
79
55
  }
80
56
  if (maxValue) {
81
- date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(maxValue));
57
+ date$1 = date.minDate(date$1, date.toCalendarDate(maxValue));
82
58
  }
83
- return date;
59
+ return date$1;
84
60
  }
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {
87
- alignCenter,
88
- alignEnd,
89
- alignStart,
90
- constrainStart,
91
- constrainValue
92
- });
61
+
62
+ exports.alignCenter = alignCenter;
63
+ exports.alignEnd = alignEnd;
64
+ exports.alignStart = alignStart;
65
+ exports.constrainStart = constrainStart;
66
+ exports.constrainValue = constrainValue;
@@ -1,14 +1,58 @@
1
- import {
2
- alignCenter,
3
- alignEnd,
4
- alignStart,
5
- constrainStart,
6
- constrainValue
7
- } from "./chunk-MGPXEJO4.mjs";
8
- export {
9
- alignCenter,
10
- alignEnd,
11
- alignStart,
12
- constrainStart,
13
- constrainValue
14
- };
1
+ import { startOfYear, startOfMonth, startOfWeek, maxDate, toCalendarDate, minDate } from '@internationalized/date';
2
+
3
+ function alignCenter(date, duration, locale, min, max) {
4
+ let halfDuration = {};
5
+ for (let key in duration) {
6
+ halfDuration[key] = Math.floor(duration[key] / 2);
7
+ if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
8
+ halfDuration[key]--;
9
+ }
10
+ }
11
+ let aligned = alignStart(date, duration, locale).subtract(halfDuration);
12
+ return constrainStart(date, aligned, duration, locale, min, max);
13
+ }
14
+ function alignStart(date, duration, locale, min, max) {
15
+ let aligned = date;
16
+ if (duration.years) {
17
+ aligned = startOfYear(date);
18
+ } else if (duration.months) {
19
+ aligned = startOfMonth(date);
20
+ } else if (duration.weeks) {
21
+ aligned = startOfWeek(date, locale);
22
+ }
23
+ return constrainStart(date, aligned, duration, locale, min, max);
24
+ }
25
+ function alignEnd(date, duration, locale, min, max) {
26
+ let d = { ...duration };
27
+ if (d.days) {
28
+ d.days--;
29
+ } else if (d.weeks) {
30
+ d.weeks--;
31
+ } else if (d.months) {
32
+ d.months--;
33
+ } else if (d.years) {
34
+ d.years--;
35
+ }
36
+ let aligned = alignStart(date, duration, locale).subtract(d);
37
+ return constrainStart(date, aligned, duration, locale, min, max);
38
+ }
39
+ function constrainStart(date, aligned, duration, locale, min, max) {
40
+ if (min && date.compare(min) >= 0) {
41
+ aligned = maxDate(aligned, alignStart(toCalendarDate(min), duration, locale));
42
+ }
43
+ if (max && date.compare(max) <= 0) {
44
+ aligned = minDate(aligned, alignEnd(toCalendarDate(max), duration, locale));
45
+ }
46
+ return aligned;
47
+ }
48
+ function constrainValue(date, minValue, maxValue) {
49
+ if (minValue) {
50
+ date = maxDate(date, toCalendarDate(minValue));
51
+ }
52
+ if (maxValue) {
53
+ date = minDate(date, toCalendarDate(maxValue));
54
+ }
55
+ return date;
56
+ }
57
+
58
+ export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue };
@@ -1,12 +1,8 @@
1
- import * as _internationalized_date from '@internationalized/date';
2
- import { DateDuration, DateValue } from '@internationalized/date';
3
-
4
- declare function getUnitDuration(duration: DateDuration): {
1
+ import type { CalendarDate, CalendarDateTime, ZonedDateTime, DateDuration, DateValue } from '@internationalized/date';
2
+ export declare function getUnitDuration(duration: DateDuration): {
5
3
  years?: number | undefined;
6
4
  months?: number | undefined;
7
5
  weeks?: number | undefined;
8
6
  days?: number | undefined;
9
7
  };
10
- declare function getEndDate(startDate: DateValue, duration: DateDuration): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
11
-
12
- export { getEndDate, getUnitDuration };
8
+ export declare function getEndDate(startDate: DateValue, duration: DateDuration): CalendarDate | CalendarDateTime | ZonedDateTime;
package/dist/duration.js CHANGED
@@ -1,29 +1,7 @@
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);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
19
4
 
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
5
  function getUnitDuration(duration) {
28
6
  let d = { ...duration };
29
7
  for (let key in d) {
@@ -40,8 +18,6 @@ function getEndDate(startDate, duration) {
40
18
  }
41
19
  return startDate.add(d);
42
20
  }
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- getEndDate,
46
- getUnitDuration
47
- });
21
+
22
+ exports.getEndDate = getEndDate;
23
+ exports.getUnitDuration = getUnitDuration;
package/dist/duration.mjs CHANGED
@@ -1,8 +1,18 @@
1
- import {
2
- getEndDate,
3
- getUnitDuration
4
- } from "./chunk-ZSLC7OI2.mjs";
5
- export {
6
- getEndDate,
7
- getUnitDuration
8
- };
1
+ function getUnitDuration(duration) {
2
+ let d = { ...duration };
3
+ for (let key in d) {
4
+ d[key] = 1;
5
+ }
6
+ return d;
7
+ }
8
+ function getEndDate(startDate, duration) {
9
+ let d = { ...duration };
10
+ if (d.days) {
11
+ d.days--;
12
+ } else {
13
+ d.days = -1;
14
+ }
15
+ return startDate.add(d);
16
+ }
17
+
18
+ export { getEndDate, getUnitDuration };
@@ -1,9 +1,6 @@
1
- import { DateValue } from '@internationalized/date';
2
-
1
+ import { type DateValue } from "@internationalized/date";
3
2
  /**
4
3
  * Formats a date using the given format string as defined in:
5
4
  * https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
6
5
  */
7
- declare function formatDate(value: DateValue, formatString: string, locale: string, timeZone?: string): string;
8
-
9
- export { formatDate };
6
+ export declare function formatDate(value: DateValue, formatString: string, locale: string, timeZone?: string): string;