@zag-js/date-utils 0.10.2 → 0.10.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.
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-end-of-week.d.ts +2 -6
  32. package/dist/get-era-format.d.ts +2 -5
  33. package/dist/get-era-format.js +5 -28
  34. package/dist/get-era-format.mjs +5 -6
  35. package/dist/get-month-days.d.ts +3 -6
  36. package/dist/get-month-days.js +13 -45
  37. package/dist/get-month-days.mjs +24 -9
  38. package/dist/get-month-formatter.d.ts +2 -5
  39. package/dist/get-month-formatter.js +10 -38
  40. package/dist/get-month-formatter.mjs +15 -7
  41. package/dist/get-month-names.d.ts +1 -3
  42. package/dist/get-month-names.js +5 -28
  43. package/dist/get-month-names.mjs +11 -6
  44. package/dist/get-start-of-week.d.ts +2 -6
  45. package/dist/get-start-of-week.js +10 -32
  46. package/dist/get-start-of-week.mjs +9 -6
  47. package/dist/get-week-days.d.ts +3 -7
  48. package/dist/get-week-days.js +8 -55
  49. package/dist/get-week-days.mjs +11 -8
  50. package/dist/get-weekday-formats.d.ts +2 -5
  51. package/dist/get-weekday-formats.js +10 -32
  52. package/dist/get-weekday-formats.mjs +18 -6
  53. package/dist/get-year-range.d.ts +2 -4
  54. package/dist/get-year-range.js +5 -28
  55. package/dist/get-year-range.mjs +9 -6
  56. package/dist/index.d.ts +20 -21
  57. package/dist/index.js +74 -740
  58. package/dist/index.mjs +19 -138
  59. package/dist/mutation.d.ts +10 -14
  60. package/dist/mutation.js +17 -59
  61. package/dist/mutation.mjs +40 -21
  62. package/dist/pagination.d.ts +19 -23
  63. package/dist/pagination.js +35 -134
  64. package/dist/pagination.mjs +179 -25
  65. package/dist/parse-date.d.ts +2 -5
  66. package/dist/parse-date.js +13 -35
  67. package/dist/parse-date.mjs +40 -6
  68. package/dist/types.d.ts +8 -11
  69. package/package.json +3 -8
  70. package/src/assertion.ts +1 -1
  71. package/src/constrain.ts +2 -2
  72. package/src/format-date.ts +1 -1
  73. package/src/format-selected-date.ts +1 -1
  74. package/src/format-visible-range.ts +1 -1
  75. package/src/get-month-days.ts +1 -1
  76. package/src/get-start-of-week.ts +1 -1
  77. package/src/get-weekday-formats.ts +1 -1
  78. package/src/mutation.ts +8 -1
  79. package/src/pagination.ts +8 -1
  80. package/dist/chunk-5HGHDJ3L.mjs +0 -14
  81. package/dist/chunk-6FNTXW54.mjs +0 -52
  82. package/dist/chunk-6LXTZHZP.mjs +0 -22
  83. package/dist/chunk-AMZ7CJ5F.mjs +0 -18
  84. package/dist/chunk-BUT5IUNZ.mjs +0 -32
  85. package/dist/chunk-FJKH6IJZ.mjs +0 -21
  86. package/dist/chunk-G4VVKINZ.mjs +0 -14
  87. package/dist/chunk-HKHGJ6WS.mjs +0 -27
  88. package/dist/chunk-HLAN6TUA.mjs +0 -45
  89. package/dist/chunk-KBGJA6NB.mjs +0 -55
  90. package/dist/chunk-KLHRN7WS.mjs +0 -20
  91. package/dist/chunk-KN3YMOSL.mjs +0 -8
  92. package/dist/chunk-KQVWH4YA.mjs +0 -29
  93. package/dist/chunk-LGEGBP3O.mjs +0 -20
  94. package/dist/chunk-MGPXEJO4.mjs +0 -71
  95. package/dist/chunk-NV7UFBMY.mjs +0 -30
  96. package/dist/chunk-POBWDZPE.mjs +0 -200
  97. package/dist/chunk-SI75FOJ2.mjs +0 -11
  98. package/dist/chunk-TTJVXKJY.mjs +0 -12
  99. package/dist/chunk-WQYMLJUJ.mjs +0 -42
  100. package/dist/chunk-ZSLC7OI2.mjs +0 -22
  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
@@ -1,200 +0,0 @@
1
- import {
2
- isDateInvalid
3
- } from "./chunk-HLAN6TUA.mjs";
4
- import {
5
- alignEnd,
6
- alignStart,
7
- constrainStart,
8
- constrainValue
9
- } from "./chunk-MGPXEJO4.mjs";
10
- import {
11
- getEndDate,
12
- getUnitDuration
13
- } from "./chunk-ZSLC7OI2.mjs";
14
-
15
- // src/pagination.ts
16
- import { endOfMonth, endOfWeek, startOfMonth, startOfWeek } from "@internationalized/date";
17
- function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
18
- return function getDate(options) {
19
- const { startDate, focusedDate } = options;
20
- const endDate = getEndDate(startDate, visibleDuration);
21
- if (isDateInvalid(focusedDate, minValue, maxValue)) {
22
- return {
23
- startDate,
24
- focusedDate: constrainValue(focusedDate, minValue, maxValue),
25
- endDate
26
- };
27
- }
28
- if (focusedDate.compare(startDate) < 0) {
29
- return {
30
- startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
31
- endDate,
32
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
33
- };
34
- }
35
- if (focusedDate.compare(endDate) > 0) {
36
- return {
37
- startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
38
- endDate,
39
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
40
- };
41
- }
42
- return {
43
- startDate,
44
- endDate,
45
- focusedDate: constrainValue(focusedDate, minValue, maxValue)
46
- };
47
- };
48
- }
49
- function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
50
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
51
- const start = startDate.add(visibleDuration);
52
- return adjust({
53
- focusedDate: focusedDate.add(visibleDuration),
54
- startDate: alignStart(
55
- constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
56
- visibleDuration,
57
- locale
58
- )
59
- });
60
- }
61
- function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
62
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
63
- let start = startDate.subtract(visibleDuration);
64
- return adjust({
65
- focusedDate: focusedDate.subtract(visibleDuration),
66
- startDate: alignStart(
67
- constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
68
- visibleDuration,
69
- locale
70
- )
71
- });
72
- }
73
- function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
74
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
75
- if (visibleDuration.days) {
76
- return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
77
- }
78
- if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
79
- return adjust({
80
- focusedDate: focusedDate.add({ weeks: 1 }),
81
- startDate
82
- });
83
- }
84
- }
85
- function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
86
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
87
- if (visibleDuration.days) {
88
- return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
89
- }
90
- if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
91
- return adjust({
92
- focusedDate: focusedDate.subtract({ weeks: 1 }),
93
- startDate
94
- });
95
- }
96
- }
97
- function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
98
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
99
- if (visibleDuration.days) {
100
- return adjust({
101
- focusedDate: startDate,
102
- startDate
103
- });
104
- }
105
- if (visibleDuration.weeks) {
106
- return adjust({
107
- focusedDate: startOfWeek(focusedDate, locale),
108
- startDate
109
- });
110
- }
111
- if (visibleDuration.months || visibleDuration.years) {
112
- return adjust({
113
- focusedDate: startOfMonth(focusedDate),
114
- startDate
115
- });
116
- }
117
- }
118
- function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
119
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
120
- const endDate = getEndDate(startDate, visibleDuration);
121
- if (visibleDuration.days) {
122
- return adjust({
123
- focusedDate: endDate,
124
- startDate
125
- });
126
- }
127
- if (visibleDuration.weeks) {
128
- return adjust({
129
- //@ts-expect-error - endOfWeek is loosely typed
130
- focusedDate: endOfWeek(focusedDate, locale),
131
- startDate
132
- });
133
- }
134
- if (visibleDuration.months || visibleDuration.years) {
135
- return adjust({
136
- focusedDate: endOfMonth(focusedDate),
137
- startDate
138
- });
139
- }
140
- }
141
- function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
142
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
143
- if (!larger && !visibleDuration.days) {
144
- return adjust({
145
- focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
146
- startDate
147
- });
148
- }
149
- if (visibleDuration.days) {
150
- return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
151
- }
152
- if (visibleDuration.weeks) {
153
- return adjust({
154
- focusedDate: focusedDate.add({ months: 1 }),
155
- startDate
156
- });
157
- }
158
- if (visibleDuration.months || visibleDuration.years) {
159
- return adjust({
160
- focusedDate: focusedDate.add({ years: 1 }),
161
- startDate
162
- });
163
- }
164
- }
165
- function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
166
- const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
167
- if (!larger && !visibleDuration.days) {
168
- return adjust({
169
- focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
170
- startDate
171
- });
172
- }
173
- if (visibleDuration.days) {
174
- return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
175
- }
176
- if (visibleDuration.weeks) {
177
- return adjust({
178
- focusedDate: focusedDate.subtract({ months: 1 }),
179
- startDate
180
- });
181
- }
182
- if (visibleDuration.months || visibleDuration.years) {
183
- return adjust({
184
- focusedDate: focusedDate.subtract({ years: 1 }),
185
- startDate
186
- });
187
- }
188
- }
189
-
190
- export {
191
- getAdjustedDateFn,
192
- getNextPage,
193
- getPreviousPage,
194
- getNextRow,
195
- getPreviousRow,
196
- getSectionStart,
197
- getSectionEnd,
198
- getNextSection,
199
- getPreviousSection
200
- };
@@ -1,11 +0,0 @@
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
- };
@@ -1,12 +0,0 @@
1
- // src/get-year-range.ts
2
- function getYearsRange(range) {
3
- const years = [];
4
- for (let year = range.from; year <= range.to; year += 1) {
5
- years.push(year);
6
- }
7
- return years;
8
- }
9
-
10
- export {
11
- getYearsRange
12
- };
@@ -1,42 +0,0 @@
1
- // src/parse-date.ts
2
- import { CalendarDateTime, 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 CalendarDateTime(+year, +month, +day);
8
- }
9
- const time = Date.parse(date);
10
- if (!isNaN(time)) {
11
- const date2 = new Date(time);
12
- return new CalendarDateTime(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
- };
@@ -1,22 +0,0 @@
1
- // src/duration.ts
2
- function getUnitDuration(duration) {
3
- let d = { ...duration };
4
- for (let key in d) {
5
- d[key] = 1;
6
- }
7
- return d;
8
- }
9
- function getEndDate(startDate, duration) {
10
- let d = { ...duration };
11
- if (d.days) {
12
- d.days--;
13
- } else {
14
- d.days = -1;
15
- }
16
- return startDate.add(d);
17
- }
18
-
19
- export {
20
- getUnitDuration,
21
- getEndDate
22
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/get-end-of-week.ts
21
- var get_end_of_week_exports = {};
22
- __export(get_end_of_week_exports, {
23
- getEndOfWeek: () => getEndOfWeek
24
- });
25
- module.exports = __toCommonJS(get_end_of_week_exports);
26
-
27
- // src/get-start-of-week.ts
28
- var import_date = require("@internationalized/date");
29
- function getStartOfWeek(date, locale, firstDayOfWeek = 0) {
30
- const day = (0, import_date.getDayOfWeek)(date, locale);
31
- const diff = (day - firstDayOfWeek + 7) % 7;
32
- return date.subtract({ days: diff });
33
- }
34
-
35
- // src/get-end-of-week.ts
36
- function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
37
- return getStartOfWeek(date, locale, firstDayOfWeek).add({ days: 6 });
38
- }
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- getEndOfWeek
42
- });
@@ -1,11 +0,0 @@
1
- import {
2
- getStartOfWeek
3
- } from "./chunk-SI75FOJ2.mjs";
4
-
5
- // src/get-end-of-week.ts
6
- function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
7
- return getStartOfWeek(date, locale, firstDayOfWeek).add({ days: 6 });
8
- }
9
- export {
10
- getEndOfWeek
11
- };
package/dist/types.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/types.ts
17
- var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
package/dist/types.mjs DELETED
File without changes