@zag-js/date-utils 1.46.0 → 1.48.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.
- package/dist/align.d.mts +4 -8
- package/dist/align.d.ts +4 -8
- package/dist/align.js +15 -47
- package/dist/align.mjs +10 -21
- package/dist/assertion.d.mts +6 -10
- package/dist/assertion.d.ts +6 -10
- package/dist/assertion.js +21 -48
- package/dist/assertion.mjs +13 -19
- package/dist/constrain.d.mts +7 -10
- package/dist/constrain.d.ts +7 -10
- package/dist/constrain.js +68 -133
- package/dist/constrain.mjs +59 -110
- package/dist/date-month.d.mts +17 -21
- package/dist/date-month.d.ts +17 -21
- package/dist/date-month.js +103 -112
- package/dist/date-month.mjs +92 -86
- package/dist/date-year.d.mts +8 -11
- package/dist/date-year.d.ts +8 -11
- package/dist/date-year.js +35 -62
- package/dist/date-year.mjs +28 -34
- package/dist/duration.d.mts +8 -12
- package/dist/duration.d.ts +8 -12
- package/dist/duration.js +13 -37
- package/dist/duration.mjs +8 -11
- package/dist/format.d.mts +5 -8
- package/dist/format.d.ts +5 -8
- package/dist/format.js +35 -76
- package/dist/format.mjs +29 -49
- package/dist/formatter.d.mts +3 -6
- package/dist/formatter.d.ts +3 -6
- package/dist/formatter.js +26 -50
- package/dist/formatter.mjs +21 -24
- package/dist/get-era-format.d.mts +2 -6
- package/dist/get-era-format.d.ts +2 -6
- package/dist/get-era-format.js +9 -34
- package/dist/get-era-format.mjs +5 -9
- package/dist/index.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +66 -47
- package/dist/index.mjs +14 -14
- package/dist/locale.d.mts +3 -5
- package/dist/locale.d.ts +3 -5
- package/dist/locale.js +28 -55
- package/dist/locale.mjs +22 -28
- package/dist/mutation.d.mts +6 -10
- package/dist/mutation.d.ts +6 -10
- package/dist/mutation.js +21 -53
- package/dist/mutation.mjs +14 -30
- package/dist/pagination.d.mts +16 -19
- package/dist/pagination.d.ts +16 -19
- package/dist/pagination.js +120 -201
- package/dist/pagination.mjs +106 -166
- package/dist/parse-date.d.mts +2 -6
- package/dist/parse-date.d.ts +2 -6
- package/dist/parse-date.js +41 -72
- package/dist/parse-date.mjs +37 -47
- package/dist/preset.d.mts +3 -6
- package/dist/preset.d.ts +3 -6
- package/dist/preset.js +23 -63
- package/dist/preset.mjs +19 -47
- package/dist/types.d.mts +17 -20
- package/dist/types.d.ts +17 -20
- package/dist/types.js +4 -18
- package/dist/types.mjs +1 -0
- package/package.json +3 -3
package/dist/parse-date.js
CHANGED
|
@@ -1,79 +1,48 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/parse-date.ts
|
|
21
|
-
var parse_date_exports = {};
|
|
22
|
-
__export(parse_date_exports, {
|
|
23
|
-
parseDateString: () => parseDateString
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
const require_date_year = require("./date-year.js");
|
|
6
|
+
let _internationalized_date = require("@internationalized/date");
|
|
7
|
+
// src/parse-date.ts
|
|
8
|
+
const isValidYear = (year) => year != null && year.length === 4;
|
|
9
|
+
const isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
10
|
+
const isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
31
11
|
function parseDateString(date, locale, timeZone) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const time = Date.parse(date);
|
|
48
|
-
if (!isNaN(time)) {
|
|
49
|
-
const date2 = new Date(time);
|
|
50
|
-
return new import_date.CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
51
|
-
}
|
|
12
|
+
let { year, month, day } = extract(createRegex(locale, timeZone), date) ?? {};
|
|
13
|
+
if (year != null || month != null || day != null) {
|
|
14
|
+
const curr = /* @__PURE__ */ new Date();
|
|
15
|
+
year || (year = curr.getFullYear().toString());
|
|
16
|
+
month || (month = (curr.getMonth() + 1).toString());
|
|
17
|
+
day || (day = curr.getDate().toString());
|
|
18
|
+
}
|
|
19
|
+
if (!isValidYear(year)) year = require_date_year.normalizeYear(year);
|
|
20
|
+
if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) return new _internationalized_date.CalendarDate(+year, +month, +day);
|
|
21
|
+
const time = Date.parse(date);
|
|
22
|
+
if (!isNaN(time)) {
|
|
23
|
+
const date = new Date(time);
|
|
24
|
+
return new _internationalized_date.CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
25
|
+
}
|
|
52
26
|
}
|
|
53
27
|
function createRegex(locale, timeZone) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
return new _internationalized_date.DateFormatter(locale, {
|
|
29
|
+
day: "numeric",
|
|
30
|
+
month: "numeric",
|
|
31
|
+
year: "numeric",
|
|
32
|
+
timeZone
|
|
33
|
+
}).formatToParts(new Date(2e3, 11, 25)).map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
|
|
57
34
|
}
|
|
58
35
|
function extract(pattern, str) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} else {
|
|
71
|
-
acc[curr] = null;
|
|
72
|
-
}
|
|
73
|
-
return acc;
|
|
74
|
-
}, {});
|
|
36
|
+
const matches = str.match(pattern);
|
|
37
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
38
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
39
|
+
if (!groupMatches || groupMatches.length <= 0) return null;
|
|
40
|
+
return group.match(/<(.+)>/)?.[1];
|
|
41
|
+
}).reduce((acc, curr, index) => {
|
|
42
|
+
if (!curr) return acc;
|
|
43
|
+
if (matches && matches.length > index) acc[curr] = matches[index + 1];
|
|
44
|
+
else acc[curr] = null;
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
75
47
|
}
|
|
76
|
-
|
|
77
|
-
0 && (module.exports = {
|
|
78
|
-
parseDateString
|
|
79
|
-
});
|
|
48
|
+
exports.parseDateString = parseDateString;
|
package/dist/parse-date.mjs
CHANGED
|
@@ -1,54 +1,44 @@
|
|
|
1
|
-
// src/parse-date.ts
|
|
2
|
-
import { CalendarDate, DateFormatter } from "@internationalized/date";
|
|
3
1
|
import { normalizeYear } from "./date-year.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { CalendarDate, DateFormatter } from "@internationalized/date";
|
|
3
|
+
// src/parse-date.ts
|
|
4
|
+
const isValidYear = (year) => year != null && year.length === 4;
|
|
5
|
+
const isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
6
|
+
const isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
7
7
|
function parseDateString(date, locale, timeZone) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
const time = Date.parse(date);
|
|
24
|
-
if (!isNaN(time)) {
|
|
25
|
-
const date2 = new Date(time);
|
|
26
|
-
return new CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
|
|
27
|
-
}
|
|
8
|
+
let { year, month, day } = extract(createRegex(locale, timeZone), date) ?? {};
|
|
9
|
+
if (year != null || month != null || day != null) {
|
|
10
|
+
const curr = /* @__PURE__ */ new Date();
|
|
11
|
+
year || (year = curr.getFullYear().toString());
|
|
12
|
+
month || (month = (curr.getMonth() + 1).toString());
|
|
13
|
+
day || (day = curr.getDate().toString());
|
|
14
|
+
}
|
|
15
|
+
if (!isValidYear(year)) year = normalizeYear(year);
|
|
16
|
+
if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) return new CalendarDate(+year, +month, +day);
|
|
17
|
+
const time = Date.parse(date);
|
|
18
|
+
if (!isNaN(time)) {
|
|
19
|
+
const date = new Date(time);
|
|
20
|
+
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
21
|
+
}
|
|
28
22
|
}
|
|
29
23
|
function createRegex(locale, timeZone) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
return new DateFormatter(locale, {
|
|
25
|
+
day: "numeric",
|
|
26
|
+
month: "numeric",
|
|
27
|
+
year: "numeric",
|
|
28
|
+
timeZone
|
|
29
|
+
}).formatToParts(new Date(2e3, 11, 25)).map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
|
|
33
30
|
}
|
|
34
31
|
function extract(pattern, str) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} else {
|
|
47
|
-
acc[curr] = null;
|
|
48
|
-
}
|
|
49
|
-
return acc;
|
|
50
|
-
}, {});
|
|
32
|
+
const matches = str.match(pattern);
|
|
33
|
+
return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
|
|
34
|
+
const groupMatches = group.match(/<(.+)>/);
|
|
35
|
+
if (!groupMatches || groupMatches.length <= 0) return null;
|
|
36
|
+
return group.match(/<(.+)>/)?.[1];
|
|
37
|
+
}).reduce((acc, curr, index) => {
|
|
38
|
+
if (!curr) return acc;
|
|
39
|
+
if (matches && matches.length > index) acc[curr] = matches[index + 1];
|
|
40
|
+
else acc[curr] = null;
|
|
41
|
+
return acc;
|
|
42
|
+
}, {});
|
|
51
43
|
}
|
|
52
|
-
export {
|
|
53
|
-
parseDateString
|
|
54
|
-
};
|
|
44
|
+
export { parseDateString };
|
package/dist/preset.d.mts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
|
5
|
-
|
|
6
|
-
export { getDateRangePreset };
|
|
1
|
+
import { DateRangePreset } from "./types.mjs";
|
|
2
|
+
import { DateValue } from "@internationalized/date";
|
|
3
|
+
export declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
package/dist/preset.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
|
5
|
-
|
|
6
|
-
export { getDateRangePreset };
|
|
1
|
+
import { DateRangePreset } from "./types.js";
|
|
2
|
+
import { DateValue } from "@internationalized/date";
|
|
3
|
+
export declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
package/dist/preset.js
CHANGED
|
@@ -1,66 +1,26 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/preset.ts
|
|
21
|
-
var preset_exports = {};
|
|
22
|
-
__export(preset_exports, {
|
|
23
|
-
getDateRangePreset: () => getDateRangePreset
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
let _internationalized_date = require("@internationalized/date");
|
|
6
|
+
// src/preset.ts
|
|
27
7
|
function getDateRangePreset(preset, locale, timeZone) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return [today.add({ days: -29 }), today];
|
|
46
|
-
case "last90Days":
|
|
47
|
-
return [today.add({ days: -89 }), today];
|
|
48
|
-
case "lastMonth":
|
|
49
|
-
return [(0, import_date.startOfMonth)(today.add({ months: -1 })), (0, import_date.endOfMonth)(today.add({ months: -1 }))];
|
|
50
|
-
case "lastQuarter":
|
|
51
|
-
return [
|
|
52
|
-
(0, import_date.startOfMonth)(today.add({ months: -((today.month - 1) % 3) - 3 })),
|
|
53
|
-
(0, import_date.endOfMonth)(today.add({ months: -((today.month - 1) % 3) - 1 }))
|
|
54
|
-
];
|
|
55
|
-
case "lastWeek":
|
|
56
|
-
return [(0, import_date.startOfWeek)(today, locale).add({ weeks: -1 }), (0, import_date.endOfWeek)(today, locale).add({ weeks: -1 })];
|
|
57
|
-
case "lastYear":
|
|
58
|
-
return [(0, import_date.startOfYear)(today.add({ years: -1 })), (0, import_date.endOfYear)(today.add({ years: -1 }))];
|
|
59
|
-
default:
|
|
60
|
-
throw new Error(`Invalid date range preset: ${preset}`);
|
|
61
|
-
}
|
|
8
|
+
const today = (0, _internationalized_date.toCalendarDate)((0, _internationalized_date.now)(timeZone));
|
|
9
|
+
switch (preset) {
|
|
10
|
+
case "thisWeek": return [(0, _internationalized_date.startOfWeek)(today, locale), (0, _internationalized_date.endOfWeek)(today, locale)];
|
|
11
|
+
case "thisMonth": return [(0, _internationalized_date.startOfMonth)(today), today];
|
|
12
|
+
case "thisQuarter": return [(0, _internationalized_date.startOfMonth)(today).add({ months: -((today.month - 1) % 3) }), today];
|
|
13
|
+
case "thisYear": return [(0, _internationalized_date.startOfYear)(today), today];
|
|
14
|
+
case "last3Days": return [today.add({ days: -2 }), today];
|
|
15
|
+
case "last7Days": return [today.add({ days: -6 }), today];
|
|
16
|
+
case "last14Days": return [today.add({ days: -13 }), today];
|
|
17
|
+
case "last30Days": return [today.add({ days: -29 }), today];
|
|
18
|
+
case "last90Days": return [today.add({ days: -89 }), today];
|
|
19
|
+
case "lastMonth": return [(0, _internationalized_date.startOfMonth)(today.add({ months: -1 })), (0, _internationalized_date.endOfMonth)(today.add({ months: -1 }))];
|
|
20
|
+
case "lastQuarter": return [(0, _internationalized_date.startOfMonth)(today.add({ months: -((today.month - 1) % 3) - 3 })), (0, _internationalized_date.endOfMonth)(today.add({ months: -((today.month - 1) % 3) - 1 }))];
|
|
21
|
+
case "lastWeek": return [(0, _internationalized_date.startOfWeek)(today, locale).add({ weeks: -1 }), (0, _internationalized_date.endOfWeek)(today, locale).add({ weeks: -1 })];
|
|
22
|
+
case "lastYear": return [(0, _internationalized_date.startOfYear)(today.add({ years: -1 })), (0, _internationalized_date.endOfYear)(today.add({ years: -1 }))];
|
|
23
|
+
default: throw new Error(`Invalid date range preset: ${preset}`);
|
|
24
|
+
}
|
|
62
25
|
}
|
|
63
|
-
|
|
64
|
-
0 && (module.exports = {
|
|
65
|
-
getDateRangePreset
|
|
66
|
-
});
|
|
26
|
+
exports.getDateRangePreset = getDateRangePreset;
|
package/dist/preset.mjs
CHANGED
|
@@ -1,50 +1,22 @@
|
|
|
1
|
+
import { endOfMonth, endOfWeek, endOfYear, now, startOfMonth, startOfWeek, startOfYear, toCalendarDate } from "@internationalized/date";
|
|
1
2
|
// src/preset.ts
|
|
2
|
-
import {
|
|
3
|
-
endOfMonth,
|
|
4
|
-
endOfWeek,
|
|
5
|
-
endOfYear,
|
|
6
|
-
now,
|
|
7
|
-
startOfMonth,
|
|
8
|
-
startOfWeek,
|
|
9
|
-
startOfYear,
|
|
10
|
-
toCalendarDate
|
|
11
|
-
} from "@internationalized/date";
|
|
12
3
|
function getDateRangePreset(preset, locale, timeZone) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return [today.add({ days: -29 }), today];
|
|
31
|
-
case "last90Days":
|
|
32
|
-
return [today.add({ days: -89 }), today];
|
|
33
|
-
case "lastMonth":
|
|
34
|
-
return [startOfMonth(today.add({ months: -1 })), endOfMonth(today.add({ months: -1 }))];
|
|
35
|
-
case "lastQuarter":
|
|
36
|
-
return [
|
|
37
|
-
startOfMonth(today.add({ months: -((today.month - 1) % 3) - 3 })),
|
|
38
|
-
endOfMonth(today.add({ months: -((today.month - 1) % 3) - 1 }))
|
|
39
|
-
];
|
|
40
|
-
case "lastWeek":
|
|
41
|
-
return [startOfWeek(today, locale).add({ weeks: -1 }), endOfWeek(today, locale).add({ weeks: -1 })];
|
|
42
|
-
case "lastYear":
|
|
43
|
-
return [startOfYear(today.add({ years: -1 })), endOfYear(today.add({ years: -1 }))];
|
|
44
|
-
default:
|
|
45
|
-
throw new Error(`Invalid date range preset: ${preset}`);
|
|
46
|
-
}
|
|
4
|
+
const today = toCalendarDate(now(timeZone));
|
|
5
|
+
switch (preset) {
|
|
6
|
+
case "thisWeek": return [startOfWeek(today, locale), endOfWeek(today, locale)];
|
|
7
|
+
case "thisMonth": return [startOfMonth(today), today];
|
|
8
|
+
case "thisQuarter": return [startOfMonth(today).add({ months: -((today.month - 1) % 3) }), today];
|
|
9
|
+
case "thisYear": return [startOfYear(today), today];
|
|
10
|
+
case "last3Days": return [today.add({ days: -2 }), today];
|
|
11
|
+
case "last7Days": return [today.add({ days: -6 }), today];
|
|
12
|
+
case "last14Days": return [today.add({ days: -13 }), today];
|
|
13
|
+
case "last30Days": return [today.add({ days: -29 }), today];
|
|
14
|
+
case "last90Days": return [today.add({ days: -89 }), today];
|
|
15
|
+
case "lastMonth": return [startOfMonth(today.add({ months: -1 })), endOfMonth(today.add({ months: -1 }))];
|
|
16
|
+
case "lastQuarter": return [startOfMonth(today.add({ months: -((today.month - 1) % 3) - 3 })), endOfMonth(today.add({ months: -((today.month - 1) % 3) - 1 }))];
|
|
17
|
+
case "lastWeek": return [startOfWeek(today, locale).add({ weeks: -1 }), endOfWeek(today, locale).add({ weeks: -1 })];
|
|
18
|
+
case "lastYear": return [startOfYear(today.add({ years: -1 })), endOfYear(today.add({ years: -1 }))];
|
|
19
|
+
default: throw new Error(`Invalid date range preset: ${preset}`);
|
|
20
|
+
}
|
|
47
21
|
}
|
|
48
|
-
export {
|
|
49
|
-
getDateRangePreset
|
|
50
|
-
};
|
|
22
|
+
export { getDateRangePreset };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { CalendarDate, CalendarDateTime,
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
locale: string;
|
|
1
|
+
import { CalendarDate, CalendarDateTime, DateFormatter, ZonedDateTime } from "@internationalized/date";
|
|
2
|
+
export type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
|
|
3
|
+
export type DateGranularity = "day" | "hour" | "minute" | "second";
|
|
4
|
+
export type DateAlignment = "start" | "end" | "center";
|
|
5
|
+
export type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
6
|
+
export type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
7
|
+
export type GetPlaceholderFn = (options: {
|
|
8
|
+
field: string;
|
|
9
|
+
locale: string;
|
|
11
10
|
}) => string;
|
|
12
|
-
type DateAdjustFn = (options: {
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export type DateAdjustFn = (options: {
|
|
12
|
+
startDate: DateValue;
|
|
13
|
+
focusedDate: DateValue;
|
|
15
14
|
}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
startDate: DateValue;
|
|
16
|
+
focusedDate: DateValue;
|
|
17
|
+
endDate: DateValue;
|
|
19
18
|
};
|
|
20
|
-
type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
21
|
-
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
22
|
-
|
|
23
|
-
export type { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity, DateRangePreset, DateValue, GetFormatterFn, GetPlaceholderFn };
|
|
19
|
+
export type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
20
|
+
export type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
package/dist/types.d.ts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { CalendarDate, CalendarDateTime,
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
locale: string;
|
|
1
|
+
import { CalendarDate, CalendarDateTime, DateFormatter, ZonedDateTime } from "@internationalized/date";
|
|
2
|
+
export type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
|
|
3
|
+
export type DateGranularity = "day" | "hour" | "minute" | "second";
|
|
4
|
+
export type DateAlignment = "start" | "end" | "center";
|
|
5
|
+
export type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
6
|
+
export type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
7
|
+
export type GetPlaceholderFn = (options: {
|
|
8
|
+
field: string;
|
|
9
|
+
locale: string;
|
|
11
10
|
}) => string;
|
|
12
|
-
type DateAdjustFn = (options: {
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export type DateAdjustFn = (options: {
|
|
12
|
+
startDate: DateValue;
|
|
13
|
+
focusedDate: DateValue;
|
|
15
14
|
}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
startDate: DateValue;
|
|
16
|
+
focusedDate: DateValue;
|
|
17
|
+
endDate: DateValue;
|
|
19
18
|
};
|
|
20
|
-
type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
21
|
-
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
22
|
-
|
|
23
|
-
export type { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity, DateRangePreset, DateValue, GetFormatterFn, GetPlaceholderFn };
|
|
19
|
+
export type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
|
|
20
|
+
export type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
package/dist/types.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
package/dist/types.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/date-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"description": "Date utilities for zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"./package.json": "./package.json"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"build": "
|
|
53
|
-
"lint": "
|
|
52
|
+
"build": "tsdown",
|
|
53
|
+
"lint": "oxlint src",
|
|
54
54
|
"typecheck": "tsc --noEmit"
|
|
55
55
|
}
|
|
56
56
|
}
|