@zag-js/date-utils 1.34.1 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/align.d.mts +8 -0
- package/dist/align.d.ts +8 -0
- package/dist/align.js +52 -0
- package/dist/align.mjs +26 -0
- package/dist/assertion.d.mts +10 -0
- package/dist/assertion.d.ts +10 -0
- package/dist/assertion.js +58 -0
- package/dist/assertion.mjs +29 -0
- package/dist/constrain.d.mts +9 -0
- package/dist/constrain.d.ts +9 -0
- package/dist/constrain.js +109 -0
- package/dist/constrain.mjs +87 -0
- package/dist/date-month.d.mts +23 -0
- package/dist/date-month.d.ts +23 -0
- package/dist/date-month.js +131 -0
- package/dist/date-month.mjs +105 -0
- package/dist/date-year.d.mts +14 -0
- package/dist/date-year.d.ts +14 -0
- package/dist/date-year.js +72 -0
- package/dist/date-year.mjs +44 -0
- package/dist/duration.d.mts +13 -0
- package/dist/duration.d.ts +13 -0
- package/dist/duration.js +42 -0
- package/dist/duration.mjs +16 -0
- package/dist/format.d.mts +8 -0
- package/dist/format.d.ts +8 -0
- package/dist/format.js +83 -0
- package/dist/format.mjs +56 -0
- package/dist/formatter.d.mts +6 -0
- package/dist/formatter.d.ts +6 -0
- package/dist/formatter.js +55 -0
- package/dist/formatter.mjs +29 -0
- package/dist/get-era-format.d.mts +6 -0
- package/dist/get-era-format.d.ts +6 -0
- package/dist/get-era-format.js +37 -0
- package/dist/get-era-format.mjs +12 -0
- package/dist/index.d.mts +14 -103
- package/dist/index.d.ts +14 -103
- package/dist/index.js +46 -637
- package/dist/index.mjs +13 -591
- package/dist/mutation.d.mts +10 -0
- package/dist/mutation.d.ts +10 -0
- package/dist/mutation.js +62 -0
- package/dist/mutation.mjs +39 -0
- package/dist/pagination.d.mts +21 -0
- package/dist/pagination.d.ts +21 -0
- package/dist/pagination.js +220 -0
- package/dist/pagination.mjs +187 -0
- package/dist/parse-date.d.mts +6 -0
- package/dist/parse-date.d.ts +6 -0
- package/dist/parse-date.js +79 -0
- package/dist/parse-date.mjs +54 -0
- package/dist/preset.d.mts +6 -0
- package/dist/preset.d.ts +6 -0
- package/dist/preset.js +66 -0
- package/dist/preset.mjs +50 -0
- package/dist/types.d.mts +23 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +1 -1
package/dist/preset.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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/preset.ts
|
|
21
|
+
var preset_exports = {};
|
|
22
|
+
__export(preset_exports, {
|
|
23
|
+
getDateRangePreset: () => getDateRangePreset
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(preset_exports);
|
|
26
|
+
var import_date = require("@internationalized/date");
|
|
27
|
+
function getDateRangePreset(preset, locale, timeZone) {
|
|
28
|
+
const today = (0, import_date.toCalendarDate)((0, import_date.now)(timeZone));
|
|
29
|
+
switch (preset) {
|
|
30
|
+
case "thisWeek":
|
|
31
|
+
return [(0, import_date.startOfWeek)(today, locale), (0, import_date.endOfWeek)(today, locale)];
|
|
32
|
+
case "thisMonth":
|
|
33
|
+
return [(0, import_date.startOfMonth)(today), today];
|
|
34
|
+
case "thisQuarter":
|
|
35
|
+
return [(0, import_date.startOfMonth)(today).add({ months: -((today.month - 1) % 3) }), today];
|
|
36
|
+
case "thisYear":
|
|
37
|
+
return [(0, import_date.startOfYear)(today), today];
|
|
38
|
+
case "last3Days":
|
|
39
|
+
return [today.add({ days: -2 }), today];
|
|
40
|
+
case "last7Days":
|
|
41
|
+
return [today.add({ days: -6 }), today];
|
|
42
|
+
case "last14Days":
|
|
43
|
+
return [today.add({ days: -13 }), today];
|
|
44
|
+
case "last30Days":
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
getDateRangePreset
|
|
66
|
+
});
|
package/dist/preset.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 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
|
+
function getDateRangePreset(preset, locale, timeZone) {
|
|
13
|
+
const today = toCalendarDate(now(timeZone));
|
|
14
|
+
switch (preset) {
|
|
15
|
+
case "thisWeek":
|
|
16
|
+
return [startOfWeek(today, locale), endOfWeek(today, locale)];
|
|
17
|
+
case "thisMonth":
|
|
18
|
+
return [startOfMonth(today), today];
|
|
19
|
+
case "thisQuarter":
|
|
20
|
+
return [startOfMonth(today).add({ months: -((today.month - 1) % 3) }), today];
|
|
21
|
+
case "thisYear":
|
|
22
|
+
return [startOfYear(today), today];
|
|
23
|
+
case "last3Days":
|
|
24
|
+
return [today.add({ days: -2 }), today];
|
|
25
|
+
case "last7Days":
|
|
26
|
+
return [today.add({ days: -6 }), today];
|
|
27
|
+
case "last14Days":
|
|
28
|
+
return [today.add({ days: -13 }), today];
|
|
29
|
+
case "last30Days":
|
|
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
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
getDateRangePreset
|
|
50
|
+
};
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CalendarDate, CalendarDateTime, ZonedDateTime, DateFormatter } from '@internationalized/date';
|
|
2
|
+
|
|
3
|
+
type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
|
|
4
|
+
type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
5
|
+
type DateAlignment = "start" | "end" | "center";
|
|
6
|
+
type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
7
|
+
type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
8
|
+
type GetPlaceholderFn = (options: {
|
|
9
|
+
field: string;
|
|
10
|
+
locale: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
type DateAdjustFn = (options: {
|
|
13
|
+
startDate: DateValue;
|
|
14
|
+
focusedDate: DateValue;
|
|
15
|
+
}) => {
|
|
16
|
+
startDate: DateValue;
|
|
17
|
+
focusedDate: DateValue;
|
|
18
|
+
endDate: DateValue;
|
|
19
|
+
};
|
|
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 };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CalendarDate, CalendarDateTime, ZonedDateTime, DateFormatter } from '@internationalized/date';
|
|
2
|
+
|
|
3
|
+
type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
|
|
4
|
+
type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
5
|
+
type DateAlignment = "start" | "end" | "center";
|
|
6
|
+
type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
|
|
7
|
+
type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
8
|
+
type GetPlaceholderFn = (options: {
|
|
9
|
+
field: string;
|
|
10
|
+
locale: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
type DateAdjustFn = (options: {
|
|
13
|
+
startDate: DateValue;
|
|
14
|
+
focusedDate: DateValue;
|
|
15
|
+
}) => {
|
|
16
|
+
startDate: DateValue;
|
|
17
|
+
focusedDate: DateValue;
|
|
18
|
+
endDate: DateValue;
|
|
19
|
+
};
|
|
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 };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
ADDED
|
File without changes
|