@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.
- package/dist/align.d.ts +4 -7
- package/dist/align.js +11 -83
- package/dist/align.mjs +24 -9
- package/dist/assertion.d.ts +10 -13
- package/dist/assertion.js +19 -48
- package/dist/assertion.mjs +36 -20
- package/dist/constrain.d.ts +6 -9
- package/dist/constrain.js +26 -52
- package/dist/constrain.mjs +58 -14
- package/dist/duration.d.ts +3 -7
- package/dist/duration.js +6 -30
- package/dist/duration.mjs +18 -8
- package/dist/format-date.d.ts +2 -5
- package/dist/format-date.js +32 -54
- package/dist/format-date.mjs +53 -6
- package/dist/format-range.d.ts +2 -5
- package/dist/format-range.js +5 -28
- package/dist/format-range.mjs +24 -6
- package/dist/format-selected-date.d.ts +2 -5
- package/dist/format-selected-date.js +10 -77
- package/dist/format-selected-date.mjs +15 -9
- package/dist/format-visible-range.d.ts +2 -5
- package/dist/format-visible-range.js +12 -68
- package/dist/format-visible-range.mjs +22 -9
- package/dist/get-day-formatter.d.ts +2 -5
- package/dist/get-day-formatter.js +9 -37
- package/dist/get-day-formatter.mjs +16 -7
- package/dist/get-decade-range.d.ts +1 -3
- package/dist/get-decade-range.js +5 -28
- package/dist/get-decade-range.mjs +11 -6
- package/dist/get-era-format.d.ts +2 -5
- package/dist/get-era-format.js +5 -28
- package/dist/get-era-format.mjs +5 -6
- package/dist/get-month-days.d.ts +3 -6
- package/dist/get-month-days.js +13 -45
- package/dist/get-month-days.mjs +24 -9
- package/dist/get-month-formatter.d.ts +2 -5
- package/dist/get-month-formatter.js +10 -38
- package/dist/get-month-formatter.mjs +15 -7
- package/dist/get-month-names.d.ts +1 -3
- package/dist/get-month-names.js +5 -28
- package/dist/get-month-names.mjs +11 -6
- package/dist/get-start-of-week.d.ts +2 -6
- package/dist/get-start-of-week.js +10 -32
- package/dist/get-start-of-week.mjs +9 -6
- package/dist/get-week-days.d.ts +3 -7
- package/dist/get-week-days.js +8 -55
- package/dist/get-week-days.mjs +11 -8
- package/dist/get-weekday-formats.d.ts +2 -5
- package/dist/get-weekday-formats.js +10 -32
- package/dist/get-weekday-formats.mjs +18 -6
- package/dist/get-year-range.d.ts +2 -4
- package/dist/get-year-range.js +5 -28
- package/dist/get-year-range.mjs +9 -6
- package/dist/index.d.ts +20 -21
- package/dist/index.js +74 -740
- package/dist/index.mjs +19 -138
- package/dist/mutation.d.ts +10 -14
- package/dist/mutation.js +17 -59
- package/dist/mutation.mjs +40 -21
- package/dist/pagination.d.ts +19 -23
- package/dist/pagination.js +35 -134
- package/dist/pagination.mjs +179 -25
- package/dist/parse-date.d.ts +2 -5
- package/dist/parse-date.js +13 -35
- package/dist/parse-date.mjs +40 -6
- package/dist/types.d.ts +8 -11
- package/package.json +2 -7
- package/src/assertion.ts +1 -1
- package/src/constrain.ts +2 -2
- package/src/format-date.ts +1 -1
- package/src/format-selected-date.ts +1 -1
- package/src/format-visible-range.ts +1 -1
- package/src/get-month-days.ts +1 -1
- package/src/get-start-of-week.ts +1 -1
- package/src/get-weekday-formats.ts +1 -1
- package/src/mutation.ts +8 -1
- package/src/pagination.ts +8 -1
- package/dist/chunk-5HGHDJ3L.mjs +0 -14
- package/dist/chunk-6FNTXW54.mjs +0 -52
- package/dist/chunk-6LXTZHZP.mjs +0 -22
- package/dist/chunk-AMZ7CJ5F.mjs +0 -18
- package/dist/chunk-BUT5IUNZ.mjs +0 -32
- package/dist/chunk-FJKH6IJZ.mjs +0 -21
- package/dist/chunk-G4VVKINZ.mjs +0 -14
- package/dist/chunk-HKHGJ6WS.mjs +0 -27
- package/dist/chunk-HLAN6TUA.mjs +0 -45
- package/dist/chunk-KBGJA6NB.mjs +0 -55
- package/dist/chunk-KLHRN7WS.mjs +0 -20
- package/dist/chunk-KN3YMOSL.mjs +0 -8
- package/dist/chunk-KQVWH4YA.mjs +0 -29
- package/dist/chunk-LGEGBP3O.mjs +0 -20
- package/dist/chunk-MGPXEJO4.mjs +0 -71
- package/dist/chunk-NV7UFBMY.mjs +0 -30
- package/dist/chunk-POBWDZPE.mjs +0 -200
- package/dist/chunk-SI75FOJ2.mjs +0 -11
- package/dist/chunk-TTJVXKJY.mjs +0 -12
- package/dist/chunk-WQYMLJUJ.mjs +0 -42
- package/dist/chunk-ZSLC7OI2.mjs +0 -22
- package/dist/get-end-of-week.d.ts +0 -6
- package/dist/get-end-of-week.js +0 -42
- package/dist/get-end-of-week.mjs +0 -11
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -0
package/dist/pagination.js
CHANGED
|
@@ -1,138 +1,41 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
21
|
-
var pagination_exports = {};
|
|
22
|
-
__export(pagination_exports, {
|
|
23
|
-
getAdjustedDateFn: () => getAdjustedDateFn,
|
|
24
|
-
getNextPage: () => getNextPage,
|
|
25
|
-
getNextRow: () => getNextRow,
|
|
26
|
-
getNextSection: () => getNextSection,
|
|
27
|
-
getPreviousPage: () => getPreviousPage,
|
|
28
|
-
getPreviousRow: () => getPreviousRow,
|
|
29
|
-
getPreviousSection: () => getPreviousSection,
|
|
30
|
-
getSectionEnd: () => getSectionEnd,
|
|
31
|
-
getSectionStart: () => getSectionStart
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(pagination_exports);
|
|
34
|
-
var import_date3 = require("@internationalized/date");
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
35
4
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
5
|
+
const date = require('@internationalized/date');
|
|
6
|
+
const assertion = require('./assertion.js');
|
|
7
|
+
const constrain = require('./constrain.js');
|
|
8
|
+
const duration = require('./duration.js');
|
|
41
9
|
|
|
42
|
-
// src/constrain.ts
|
|
43
|
-
var import_date2 = require("@internationalized/date");
|
|
44
|
-
function alignStart(date, duration, locale, min, max) {
|
|
45
|
-
let aligned = date;
|
|
46
|
-
if (duration.years) {
|
|
47
|
-
aligned = (0, import_date2.startOfYear)(date);
|
|
48
|
-
} else if (duration.months) {
|
|
49
|
-
aligned = (0, import_date2.startOfMonth)(date);
|
|
50
|
-
} else if (duration.weeks) {
|
|
51
|
-
aligned = (0, import_date2.startOfWeek)(date, locale);
|
|
52
|
-
}
|
|
53
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
54
|
-
}
|
|
55
|
-
function alignEnd(date, duration, locale, min, max) {
|
|
56
|
-
let d = { ...duration };
|
|
57
|
-
if (d.days) {
|
|
58
|
-
d.days--;
|
|
59
|
-
} else if (d.weeks) {
|
|
60
|
-
d.weeks--;
|
|
61
|
-
} else if (d.months) {
|
|
62
|
-
d.months--;
|
|
63
|
-
} else if (d.years) {
|
|
64
|
-
d.years--;
|
|
65
|
-
}
|
|
66
|
-
let aligned = alignStart(date, duration, locale).subtract(d);
|
|
67
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
68
|
-
}
|
|
69
|
-
function constrainStart(date, aligned, duration, locale, min, max) {
|
|
70
|
-
if (min && date.compare(min) >= 0) {
|
|
71
|
-
aligned = (0, import_date2.maxDate)(aligned, alignStart((0, import_date2.toCalendarDate)(min), duration, locale));
|
|
72
|
-
}
|
|
73
|
-
if (max && date.compare(max) <= 0) {
|
|
74
|
-
aligned = (0, import_date2.minDate)(aligned, alignEnd((0, import_date2.toCalendarDate)(max), duration, locale));
|
|
75
|
-
}
|
|
76
|
-
return aligned;
|
|
77
|
-
}
|
|
78
|
-
function constrainValue(date, minValue, maxValue) {
|
|
79
|
-
if (minValue) {
|
|
80
|
-
date = (0, import_date2.maxDate)(date, (0, import_date2.toCalendarDate)(minValue));
|
|
81
|
-
}
|
|
82
|
-
if (maxValue) {
|
|
83
|
-
date = (0, import_date2.minDate)(date, (0, import_date2.toCalendarDate)(maxValue));
|
|
84
|
-
}
|
|
85
|
-
return date;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/duration.ts
|
|
89
|
-
function getUnitDuration(duration) {
|
|
90
|
-
let d = { ...duration };
|
|
91
|
-
for (let key in d) {
|
|
92
|
-
d[key] = 1;
|
|
93
|
-
}
|
|
94
|
-
return d;
|
|
95
|
-
}
|
|
96
|
-
function getEndDate(startDate, duration) {
|
|
97
|
-
let d = { ...duration };
|
|
98
|
-
if (d.days) {
|
|
99
|
-
d.days--;
|
|
100
|
-
} else {
|
|
101
|
-
d.days = -1;
|
|
102
|
-
}
|
|
103
|
-
return startDate.add(d);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/pagination.ts
|
|
107
10
|
function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
|
|
108
11
|
return function getDate(options) {
|
|
109
12
|
const { startDate, focusedDate } = options;
|
|
110
|
-
const endDate = getEndDate(startDate, visibleDuration);
|
|
111
|
-
if (isDateInvalid(focusedDate, minValue, maxValue)) {
|
|
13
|
+
const endDate = duration.getEndDate(startDate, visibleDuration);
|
|
14
|
+
if (assertion.isDateInvalid(focusedDate, minValue, maxValue)) {
|
|
112
15
|
return {
|
|
113
16
|
startDate,
|
|
114
|
-
focusedDate: constrainValue(focusedDate, minValue, maxValue),
|
|
17
|
+
focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue),
|
|
115
18
|
endDate
|
|
116
19
|
};
|
|
117
20
|
}
|
|
118
21
|
if (focusedDate.compare(startDate) < 0) {
|
|
119
22
|
return {
|
|
120
|
-
startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
23
|
+
startDate: constrain.alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
121
24
|
endDate,
|
|
122
|
-
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
25
|
+
focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue)
|
|
123
26
|
};
|
|
124
27
|
}
|
|
125
28
|
if (focusedDate.compare(endDate) > 0) {
|
|
126
29
|
return {
|
|
127
|
-
startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
30
|
+
startDate: constrain.alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
128
31
|
endDate,
|
|
129
|
-
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
32
|
+
focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue)
|
|
130
33
|
};
|
|
131
34
|
}
|
|
132
35
|
return {
|
|
133
36
|
startDate,
|
|
134
37
|
endDate,
|
|
135
|
-
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
38
|
+
focusedDate: constrain.constrainValue(focusedDate, minValue, maxValue)
|
|
136
39
|
};
|
|
137
40
|
};
|
|
138
41
|
}
|
|
@@ -141,8 +44,8 @@ function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue,
|
|
|
141
44
|
const start = startDate.add(visibleDuration);
|
|
142
45
|
return adjust({
|
|
143
46
|
focusedDate: focusedDate.add(visibleDuration),
|
|
144
|
-
startDate: alignStart(
|
|
145
|
-
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
47
|
+
startDate: constrain.alignStart(
|
|
48
|
+
constrain.constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
146
49
|
visibleDuration,
|
|
147
50
|
locale
|
|
148
51
|
)
|
|
@@ -153,8 +56,8 @@ function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minVal
|
|
|
153
56
|
let start = startDate.subtract(visibleDuration);
|
|
154
57
|
return adjust({
|
|
155
58
|
focusedDate: focusedDate.subtract(visibleDuration),
|
|
156
|
-
startDate: alignStart(
|
|
157
|
-
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
59
|
+
startDate: constrain.alignStart(
|
|
60
|
+
constrain.constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
158
61
|
visibleDuration,
|
|
159
62
|
locale
|
|
160
63
|
)
|
|
@@ -194,20 +97,20 @@ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minVal
|
|
|
194
97
|
}
|
|
195
98
|
if (visibleDuration.weeks) {
|
|
196
99
|
return adjust({
|
|
197
|
-
focusedDate:
|
|
100
|
+
focusedDate: date.startOfWeek(focusedDate, locale),
|
|
198
101
|
startDate
|
|
199
102
|
});
|
|
200
103
|
}
|
|
201
104
|
if (visibleDuration.months || visibleDuration.years) {
|
|
202
105
|
return adjust({
|
|
203
|
-
focusedDate:
|
|
106
|
+
focusedDate: date.startOfMonth(focusedDate),
|
|
204
107
|
startDate
|
|
205
108
|
});
|
|
206
109
|
}
|
|
207
110
|
}
|
|
208
111
|
function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
209
112
|
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
210
|
-
const endDate = getEndDate(startDate, visibleDuration);
|
|
113
|
+
const endDate = duration.getEndDate(startDate, visibleDuration);
|
|
211
114
|
if (visibleDuration.days) {
|
|
212
115
|
return adjust({
|
|
213
116
|
focusedDate: endDate,
|
|
@@ -217,13 +120,13 @@ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue
|
|
|
217
120
|
if (visibleDuration.weeks) {
|
|
218
121
|
return adjust({
|
|
219
122
|
//@ts-expect-error - endOfWeek is loosely typed
|
|
220
|
-
focusedDate:
|
|
123
|
+
focusedDate: date.endOfWeek(focusedDate, locale),
|
|
221
124
|
startDate
|
|
222
125
|
});
|
|
223
126
|
}
|
|
224
127
|
if (visibleDuration.months || visibleDuration.years) {
|
|
225
128
|
return adjust({
|
|
226
|
-
focusedDate:
|
|
129
|
+
focusedDate: date.endOfMonth(focusedDate),
|
|
227
130
|
startDate
|
|
228
131
|
});
|
|
229
132
|
}
|
|
@@ -232,7 +135,7 @@ function getNextSection(focusedDate, startDate, larger, visibleDuration, locale,
|
|
|
232
135
|
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
233
136
|
if (!larger && !visibleDuration.days) {
|
|
234
137
|
return adjust({
|
|
235
|
-
focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
|
|
138
|
+
focusedDate: focusedDate.add(duration.getUnitDuration(visibleDuration)),
|
|
236
139
|
startDate
|
|
237
140
|
});
|
|
238
141
|
}
|
|
@@ -256,7 +159,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
256
159
|
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
257
160
|
if (!larger && !visibleDuration.days) {
|
|
258
161
|
return adjust({
|
|
259
|
-
focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
|
|
162
|
+
focusedDate: focusedDate.subtract(duration.getUnitDuration(visibleDuration)),
|
|
260
163
|
startDate
|
|
261
164
|
});
|
|
262
165
|
}
|
|
@@ -276,15 +179,13 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
276
179
|
});
|
|
277
180
|
}
|
|
278
181
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
getSectionStart
|
|
290
|
-
});
|
|
182
|
+
|
|
183
|
+
exports.getAdjustedDateFn = getAdjustedDateFn;
|
|
184
|
+
exports.getNextPage = getNextPage;
|
|
185
|
+
exports.getNextRow = getNextRow;
|
|
186
|
+
exports.getNextSection = getNextSection;
|
|
187
|
+
exports.getPreviousPage = getPreviousPage;
|
|
188
|
+
exports.getPreviousRow = getPreviousRow;
|
|
189
|
+
exports.getPreviousSection = getPreviousSection;
|
|
190
|
+
exports.getSectionEnd = getSectionEnd;
|
|
191
|
+
exports.getSectionStart = getSectionStart;
|
package/dist/pagination.mjs
CHANGED
|
@@ -1,25 +1,179 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { startOfWeek, startOfMonth, endOfWeek, endOfMonth } from '@internationalized/date';
|
|
2
|
+
import { isDateInvalid } from './assertion.mjs';
|
|
3
|
+
import { constrainValue, alignEnd, alignStart, constrainStart } from './constrain.mjs';
|
|
4
|
+
import { getEndDate, getUnitDuration } from './duration.mjs';
|
|
5
|
+
|
|
6
|
+
function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
|
|
7
|
+
return function getDate(options) {
|
|
8
|
+
const { startDate, focusedDate } = options;
|
|
9
|
+
const endDate = getEndDate(startDate, visibleDuration);
|
|
10
|
+
if (isDateInvalid(focusedDate, minValue, maxValue)) {
|
|
11
|
+
return {
|
|
12
|
+
startDate,
|
|
13
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue),
|
|
14
|
+
endDate
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
18
|
+
return {
|
|
19
|
+
startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
20
|
+
endDate,
|
|
21
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
25
|
+
return {
|
|
26
|
+
startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
|
|
27
|
+
endDate,
|
|
28
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
startDate,
|
|
33
|
+
endDate,
|
|
34
|
+
focusedDate: constrainValue(focusedDate, minValue, maxValue)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
39
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
40
|
+
const start = startDate.add(visibleDuration);
|
|
41
|
+
return adjust({
|
|
42
|
+
focusedDate: focusedDate.add(visibleDuration),
|
|
43
|
+
startDate: alignStart(
|
|
44
|
+
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
45
|
+
visibleDuration,
|
|
46
|
+
locale
|
|
47
|
+
)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
51
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
52
|
+
let start = startDate.subtract(visibleDuration);
|
|
53
|
+
return adjust({
|
|
54
|
+
focusedDate: focusedDate.subtract(visibleDuration),
|
|
55
|
+
startDate: alignStart(
|
|
56
|
+
constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
|
|
57
|
+
visibleDuration,
|
|
58
|
+
locale
|
|
59
|
+
)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
63
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
64
|
+
if (visibleDuration.days) {
|
|
65
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
66
|
+
}
|
|
67
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
68
|
+
return adjust({
|
|
69
|
+
focusedDate: focusedDate.add({ weeks: 1 }),
|
|
70
|
+
startDate
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
75
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
76
|
+
if (visibleDuration.days) {
|
|
77
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
78
|
+
}
|
|
79
|
+
if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
80
|
+
return adjust({
|
|
81
|
+
focusedDate: focusedDate.subtract({ weeks: 1 }),
|
|
82
|
+
startDate
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
87
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
88
|
+
if (visibleDuration.days) {
|
|
89
|
+
return adjust({
|
|
90
|
+
focusedDate: startDate,
|
|
91
|
+
startDate
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (visibleDuration.weeks) {
|
|
95
|
+
return adjust({
|
|
96
|
+
focusedDate: startOfWeek(focusedDate, locale),
|
|
97
|
+
startDate
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
101
|
+
return adjust({
|
|
102
|
+
focusedDate: startOfMonth(focusedDate),
|
|
103
|
+
startDate
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
|
|
108
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
109
|
+
const endDate = getEndDate(startDate, visibleDuration);
|
|
110
|
+
if (visibleDuration.days) {
|
|
111
|
+
return adjust({
|
|
112
|
+
focusedDate: endDate,
|
|
113
|
+
startDate
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (visibleDuration.weeks) {
|
|
117
|
+
return adjust({
|
|
118
|
+
//@ts-expect-error - endOfWeek is loosely typed
|
|
119
|
+
focusedDate: endOfWeek(focusedDate, locale),
|
|
120
|
+
startDate
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
124
|
+
return adjust({
|
|
125
|
+
focusedDate: endOfMonth(focusedDate),
|
|
126
|
+
startDate
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
131
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
132
|
+
if (!larger && !visibleDuration.days) {
|
|
133
|
+
return adjust({
|
|
134
|
+
focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
|
|
135
|
+
startDate
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (visibleDuration.days) {
|
|
139
|
+
return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
140
|
+
}
|
|
141
|
+
if (visibleDuration.weeks) {
|
|
142
|
+
return adjust({
|
|
143
|
+
focusedDate: focusedDate.add({ months: 1 }),
|
|
144
|
+
startDate
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
148
|
+
return adjust({
|
|
149
|
+
focusedDate: focusedDate.add({ years: 1 }),
|
|
150
|
+
startDate
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
|
|
155
|
+
const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
|
|
156
|
+
if (!larger && !visibleDuration.days) {
|
|
157
|
+
return adjust({
|
|
158
|
+
focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
|
|
159
|
+
startDate
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (visibleDuration.days) {
|
|
163
|
+
return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
|
|
164
|
+
}
|
|
165
|
+
if (visibleDuration.weeks) {
|
|
166
|
+
return adjust({
|
|
167
|
+
focusedDate: focusedDate.subtract({ months: 1 }),
|
|
168
|
+
startDate
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (visibleDuration.months || visibleDuration.years) {
|
|
172
|
+
return adjust({
|
|
173
|
+
focusedDate: focusedDate.subtract({ years: 1 }),
|
|
174
|
+
startDate
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
|
package/dist/parse-date.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import { CalendarDateTime } from
|
|
2
|
-
|
|
3
|
-
declare function parseDateString(date: string, locale: string, timeZone: string): CalendarDateTime | undefined;
|
|
4
|
-
|
|
5
|
-
export { parseDateString };
|
|
1
|
+
import { CalendarDateTime } from "@internationalized/date";
|
|
2
|
+
export declare function parseDateString(date: string, locale: string, timeZone: string): CalendarDateTime | undefined;
|
package/dist/parse-date.js
CHANGED
|
@@ -1,43 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
parseDateString: () => parseDateString
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(parse_date_exports);
|
|
26
|
-
var import_date = require("@internationalized/date");
|
|
27
|
-
function parseDateString(date, locale, timeZone) {
|
|
5
|
+
const date = require('@internationalized/date');
|
|
6
|
+
|
|
7
|
+
function parseDateString(date$1, locale, timeZone) {
|
|
28
8
|
const regex = createRegex(locale, timeZone);
|
|
29
|
-
const { year, month, day } = extract(regex, date) ?? {};
|
|
9
|
+
const { year, month, day } = extract(regex, date$1) ?? {};
|
|
30
10
|
if (year != null && year.length === 4 && month != null && +month <= 12 && day != null && +day <= 31) {
|
|
31
|
-
return new
|
|
11
|
+
return new date.CalendarDateTime(+year, +month, +day);
|
|
32
12
|
}
|
|
33
|
-
const time = Date.parse(date);
|
|
13
|
+
const time = Date.parse(date$1);
|
|
34
14
|
if (!isNaN(time)) {
|
|
35
15
|
const date2 = new Date(time);
|
|
36
|
-
return new
|
|
16
|
+
return new date.CalendarDateTime(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
37
17
|
}
|
|
38
18
|
}
|
|
39
19
|
function createRegex(locale, timeZone) {
|
|
40
|
-
const formatter = new
|
|
20
|
+
const formatter = new date.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
|
|
41
21
|
const parts = formatter.formatToParts(new Date(2e3, 11, 25));
|
|
42
22
|
return parts.map(({ type, value }) => type === "literal" ? value : `((?!=<${type}>)\\d+)`).join("");
|
|
43
23
|
}
|
|
@@ -60,7 +40,5 @@ function extract(pattern, str) {
|
|
|
60
40
|
return acc;
|
|
61
41
|
}, {});
|
|
62
42
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
parseDateString
|
|
66
|
-
});
|
|
43
|
+
|
|
44
|
+
exports.parseDateString = parseDateString;
|
package/dist/parse-date.mjs
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { CalendarDateTime, DateFormatter } from '@internationalized/date';
|
|
2
|
+
|
|
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 { parseDateString };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { DateFormatter, DateValue } from
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type GetPlaceholderFn = (options: {
|
|
1
|
+
import type { DateFormatter, DateValue } from "@internationalized/date";
|
|
2
|
+
export type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
3
|
+
export type DateAlignment = "start" | "end" | "center";
|
|
4
|
+
export type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
5
|
+
export type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
6
|
+
export type GetPlaceholderFn = (options: {
|
|
8
7
|
field: string;
|
|
9
8
|
locale: string;
|
|
10
9
|
}) => string;
|
|
11
|
-
type DateAdjustFn = (options: {
|
|
10
|
+
export type DateAdjustFn = (options: {
|
|
12
11
|
startDate: DateValue;
|
|
13
12
|
focusedDate: DateValue;
|
|
14
13
|
}) => {
|
|
@@ -16,6 +15,4 @@ type DateAdjustFn = (options: {
|
|
|
16
15
|
focusedDate: DateValue;
|
|
17
16
|
endDate: DateValue;
|
|
18
17
|
};
|
|
19
|
-
type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
20
|
-
|
|
21
|
-
export { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity, GetFormatterFn, GetPlaceholderFn };
|
|
18
|
+
export type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/date-utils",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "Date utilities for zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -42,13 +42,8 @@
|
|
|
42
42
|
"./package.json": "./package.json"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"build
|
|
46
|
-
"start": "pnpm build --watch",
|
|
47
|
-
"build": "tsup src --dts",
|
|
48
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
45
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
49
46
|
"lint": "eslint src --ext .ts,.tsx",
|
|
50
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
51
|
-
"test-watch": "pnpm test --watch -u",
|
|
52
47
|
"typecheck": "tsc --noEmit"
|
|
53
48
|
}
|
|
54
49
|
}
|
package/src/assertion.ts
CHANGED
package/src/constrain.ts
CHANGED
package/src/format-date.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateValue, endOfMonth, isSameDay, startOfMonth } from "@internationalized/date"
|
|
1
|
+
import { type DateValue, endOfMonth, isSameDay, startOfMonth } from "@internationalized/date"
|
|
2
2
|
import { getDayFormatter } from "./get-day-formatter"
|
|
3
3
|
import { getMonthFormatter } from "./get-month-formatter"
|
|
4
4
|
|