@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/align.d.mts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DateDuration } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
|
|
6
|
-
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
7
|
-
|
|
8
|
-
export { alignDate, alignStartDate };
|
|
1
|
+
import { DateAlignment, DateValue as DateValue$1 } from "./types.mjs";
|
|
2
|
+
import { DateDuration } from "@internationalized/date";
|
|
3
|
+
export declare function alignDate(date: DateValue$1, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): import("@internationalized/date").DateValue;
|
|
4
|
+
export declare function alignStartDate(date: DateValue$1, startDate: DateValue$1, endDate: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): import("@internationalized/date").CalendarDate | import("@internationalized/date").CalendarDateTime | import("@internationalized/date").ZonedDateTime;
|
package/dist/align.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DateDuration } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
|
|
6
|
-
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
7
|
-
|
|
8
|
-
export { alignDate, alignStartDate };
|
|
1
|
+
import { DateAlignment, DateValue as DateValue$1 } from "./types.js";
|
|
2
|
+
import { DateDuration } from "@internationalized/date";
|
|
3
|
+
export declare function alignDate(date: DateValue$1, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): import("@internationalized/date").DateValue;
|
|
4
|
+
export declare function alignStartDate(date: DateValue$1, startDate: DateValue$1, endDate: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): import("@internationalized/date").CalendarDate | import("@internationalized/date").CalendarDateTime | import("@internationalized/date").ZonedDateTime;
|
package/dist/align.js
CHANGED
|
@@ -1,52 +1,20 @@
|
|
|
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/align.ts
|
|
21
|
-
var align_exports = {};
|
|
22
|
-
__export(align_exports, {
|
|
23
|
-
alignDate: () => alignDate,
|
|
24
|
-
alignStartDate: () => alignStartDate
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
25
4
|
});
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
const require_constrain = require("./constrain.js");
|
|
6
|
+
// src/align.ts
|
|
28
7
|
function alignDate(date, alignment, duration, locale, min, max) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
case "center":
|
|
35
|
-
default:
|
|
36
|
-
return (0, import_constrain.alignCenter)(date, duration, locale, min, max);
|
|
37
|
-
}
|
|
8
|
+
switch (alignment) {
|
|
9
|
+
case "start": return require_constrain.alignStart(date, duration, locale, min, max);
|
|
10
|
+
case "end": return require_constrain.alignEnd(date, duration, locale, min, max);
|
|
11
|
+
default: return require_constrain.alignCenter(date, duration, locale, min, max);
|
|
12
|
+
}
|
|
38
13
|
}
|
|
39
14
|
function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (date.compare(endDate) > 0) {
|
|
44
|
-
return (0, import_constrain.alignStart)(date, duration, locale, min, max);
|
|
45
|
-
}
|
|
46
|
-
return startDate;
|
|
15
|
+
if (date.compare(startDate) < 0) return require_constrain.alignEnd(date, duration, locale, min, max);
|
|
16
|
+
if (date.compare(endDate) > 0) return require_constrain.alignStart(date, duration, locale, min, max);
|
|
17
|
+
return startDate;
|
|
47
18
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
alignDate,
|
|
51
|
-
alignStartDate
|
|
52
|
-
});
|
|
19
|
+
exports.alignDate = alignDate;
|
|
20
|
+
exports.alignStartDate = alignStartDate;
|
package/dist/align.mjs
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
// src/align.ts
|
|
2
1
|
import { alignCenter, alignEnd, alignStart } from "./constrain.mjs";
|
|
2
|
+
// src/align.ts
|
|
3
3
|
function alignDate(date, alignment, duration, locale, min, max) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
case "center":
|
|
10
|
-
default:
|
|
11
|
-
return alignCenter(date, duration, locale, min, max);
|
|
12
|
-
}
|
|
4
|
+
switch (alignment) {
|
|
5
|
+
case "start": return alignStart(date, duration, locale, min, max);
|
|
6
|
+
case "end": return alignEnd(date, duration, locale, min, max);
|
|
7
|
+
default: return alignCenter(date, duration, locale, min, max);
|
|
8
|
+
}
|
|
13
9
|
}
|
|
14
10
|
function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (date.compare(endDate) > 0) {
|
|
19
|
-
return alignStart(date, duration, locale, min, max);
|
|
20
|
-
}
|
|
21
|
-
return startDate;
|
|
11
|
+
if (date.compare(startDate) < 0) return alignEnd(date, duration, locale, min, max);
|
|
12
|
+
if (date.compare(endDate) > 0) return alignStart(date, duration, locale, min, max);
|
|
13
|
+
return startDate;
|
|
22
14
|
}
|
|
23
|
-
export {
|
|
24
|
-
alignDate,
|
|
25
|
-
alignStartDate
|
|
26
|
-
};
|
|
15
|
+
export { alignDate, alignStartDate };
|
package/dist/assertion.d.mts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
8
|
-
declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
9
|
-
|
|
10
|
-
export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
|
|
1
|
+
import { DateAvailableFn, DateValue } from "./types.mjs";
|
|
2
|
+
export declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
|
|
3
|
+
export declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
4
|
+
export declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
|
|
5
|
+
export declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
6
|
+
export declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
package/dist/assertion.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
8
|
-
declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
9
|
-
|
|
10
|
-
export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
|
|
1
|
+
import { DateAvailableFn, DateValue } from "./types.js";
|
|
2
|
+
export declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
|
|
3
|
+
export declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
4
|
+
export declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
|
|
5
|
+
export declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
6
|
+
export declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
package/dist/assertion.js
CHANGED
|
@@ -1,59 +1,32 @@
|
|
|
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/assertion.ts
|
|
21
|
-
var assertion_exports = {};
|
|
22
|
-
__export(assertion_exports, {
|
|
23
|
-
isDateEqual: () => isDateEqual,
|
|
24
|
-
isDateOutsideRange: () => isDateOutsideRange,
|
|
25
|
-
isDateUnavailable: () => isDateUnavailable,
|
|
26
|
-
isNextRangeInvalid: () => isNextRangeInvalid,
|
|
27
|
-
isPreviousRangeInvalid: () => isPreviousRangeInvalid
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
28
4
|
});
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
let _internationalized_date = require("@internationalized/date");
|
|
6
|
+
// src/assertion.ts
|
|
31
7
|
function isDateEqual(dateA, dateB) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
if (dateA == null || dateB == null) return dateA === dateB;
|
|
9
|
+
if (!("hour" in dateA) && !("hour" in dateB)) return (0, _internationalized_date.isSameDay)(dateA, dateB);
|
|
10
|
+
return (0, _internationalized_date.toCalendarDateTime)(dateA).compare((0, _internationalized_date.toCalendarDateTime)(dateB)) === 0;
|
|
35
11
|
}
|
|
36
12
|
function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
13
|
+
if (!date) return false;
|
|
14
|
+
if (isUnavailable?.(date, locale)) return true;
|
|
15
|
+
return isDateOutsideRange(date, minValue, maxValue);
|
|
40
16
|
}
|
|
41
17
|
function isDateOutsideRange(date, startDate, endDate) {
|
|
42
|
-
|
|
18
|
+
return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
|
|
43
19
|
}
|
|
44
20
|
function isPreviousRangeInvalid(startDate, minValue, maxValue) {
|
|
45
|
-
|
|
46
|
-
|
|
21
|
+
const prevDate = startDate.subtract({ days: 1 });
|
|
22
|
+
return (0, _internationalized_date.isSameDay)(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
|
|
47
23
|
}
|
|
48
24
|
function isNextRangeInvalid(endDate, minValue, maxValue) {
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
const nextDate = endDate.add({ days: 1 });
|
|
26
|
+
return (0, _internationalized_date.isSameDay)(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
|
|
51
27
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
isNextRangeInvalid,
|
|
58
|
-
isPreviousRangeInvalid
|
|
59
|
-
});
|
|
28
|
+
exports.isDateEqual = isDateEqual;
|
|
29
|
+
exports.isDateOutsideRange = isDateOutsideRange;
|
|
30
|
+
exports.isDateUnavailable = isDateUnavailable;
|
|
31
|
+
exports.isNextRangeInvalid = isNextRangeInvalid;
|
|
32
|
+
exports.isPreviousRangeInvalid = isPreviousRangeInvalid;
|
package/dist/assertion.mjs
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
// src/assertion.ts
|
|
2
1
|
import { isSameDay, toCalendarDateTime } from "@internationalized/date";
|
|
2
|
+
// src/assertion.ts
|
|
3
3
|
function isDateEqual(dateA, dateB) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (dateA == null || dateB == null) return dateA === dateB;
|
|
5
|
+
if (!("hour" in dateA) && !("hour" in dateB)) return isSameDay(dateA, dateB);
|
|
6
|
+
return toCalendarDateTime(dateA).compare(toCalendarDateTime(dateB)) === 0;
|
|
7
7
|
}
|
|
8
8
|
function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!date) return false;
|
|
10
|
+
if (isUnavailable?.(date, locale)) return true;
|
|
11
|
+
return isDateOutsideRange(date, minValue, maxValue);
|
|
12
12
|
}
|
|
13
13
|
function isDateOutsideRange(date, startDate, endDate) {
|
|
14
|
-
|
|
14
|
+
return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
|
|
15
15
|
}
|
|
16
16
|
function isPreviousRangeInvalid(startDate, minValue, maxValue) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const prevDate = startDate.subtract({ days: 1 });
|
|
18
|
+
return isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
|
|
19
19
|
}
|
|
20
20
|
function isNextRangeInvalid(endDate, minValue, maxValue) {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const nextDate = endDate.add({ days: 1 });
|
|
22
|
+
return isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
|
|
23
23
|
}
|
|
24
|
-
export {
|
|
25
|
-
isDateEqual,
|
|
26
|
-
isDateOutsideRange,
|
|
27
|
-
isDateUnavailable,
|
|
28
|
-
isNextRangeInvalid,
|
|
29
|
-
isPreviousRangeInvalid
|
|
30
|
-
};
|
|
24
|
+
export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
|
package/dist/constrain.d.mts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
8
|
-
declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
|
|
9
|
-
|
|
10
|
-
export { alignCenter, alignEnd, alignStart, constrainSegments, constrainStart, constrainValue };
|
|
1
|
+
import { DateDuration, 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<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
|
|
7
|
+
export declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
|
package/dist/constrain.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
8
|
-
declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
|
|
9
|
-
|
|
10
|
-
export { alignCenter, alignEnd, alignStart, constrainSegments, constrainStart, constrainValue };
|
|
1
|
+
import { DateDuration, 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<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
|
|
7
|
+
export declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
|
package/dist/constrain.js
CHANGED
|
@@ -1,146 +1,81 @@
|
|
|
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/constrain.ts
|
|
21
|
-
var constrain_exports = {};
|
|
22
|
-
__export(constrain_exports, {
|
|
23
|
-
alignCenter: () => alignCenter,
|
|
24
|
-
alignEnd: () => alignEnd,
|
|
25
|
-
alignStart: () => alignStart,
|
|
26
|
-
constrainSegments: () => constrainSegments,
|
|
27
|
-
constrainStart: () => constrainStart,
|
|
28
|
-
constrainValue: () => constrainValue
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
29
4
|
});
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
let _internationalized_date = require("@internationalized/date");
|
|
6
|
+
// src/constrain.ts
|
|
32
7
|
function alignCenter(date, duration, locale, min, max) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
const aligned = alignStart(date, duration, locale).subtract(halfDuration);
|
|
44
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
8
|
+
const halfDuration = {};
|
|
9
|
+
for (let prop in duration) {
|
|
10
|
+
const key = prop;
|
|
11
|
+
const value = duration[key];
|
|
12
|
+
if (value == null) continue;
|
|
13
|
+
halfDuration[key] = Math.floor(value / 2);
|
|
14
|
+
if (halfDuration[key] > 0 && value % 2 === 0) halfDuration[key]--;
|
|
15
|
+
}
|
|
16
|
+
return constrainStart(date, alignStart(date, duration, locale).subtract(halfDuration), duration, locale, min, max);
|
|
45
17
|
}
|
|
46
18
|
function alignStart(date, duration, locale, min, max) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} else if (duration.weeks) {
|
|
53
|
-
aligned = (0, import_date.startOfWeek)(date, locale);
|
|
54
|
-
}
|
|
55
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
19
|
+
let aligned = date;
|
|
20
|
+
if (duration.years) aligned = (0, _internationalized_date.startOfYear)(date);
|
|
21
|
+
else if (duration.months) aligned = (0, _internationalized_date.startOfMonth)(date);
|
|
22
|
+
else if (duration.weeks) aligned = (0, _internationalized_date.startOfWeek)(date, locale);
|
|
23
|
+
return constrainStart(date, aligned, duration, locale, min, max);
|
|
56
24
|
}
|
|
57
25
|
function alignEnd(date, duration, locale, min, max) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
d.months--;
|
|
65
|
-
} else if (d.years) {
|
|
66
|
-
d.years--;
|
|
67
|
-
}
|
|
68
|
-
let aligned = alignStart(date, duration, locale).subtract(d);
|
|
69
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
26
|
+
let d = { ...duration };
|
|
27
|
+
if (d.days) d.days--;
|
|
28
|
+
else if (d.weeks) d.weeks--;
|
|
29
|
+
else if (d.months) d.months--;
|
|
30
|
+
else if (d.years) d.years--;
|
|
31
|
+
return constrainStart(date, alignStart(date, duration, locale).subtract(d), duration, locale, min, max);
|
|
70
32
|
}
|
|
71
33
|
function constrainStart(date, aligned, duration, locale, min, max) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (max && date.compare(max) <= 0) {
|
|
76
|
-
aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
|
|
77
|
-
}
|
|
78
|
-
return aligned;
|
|
34
|
+
if (min && date.compare(min) >= 0) aligned = (0, _internationalized_date.maxDate)(aligned, alignStart((0, _internationalized_date.toCalendarDate)(min), duration, locale));
|
|
35
|
+
if (max && date.compare(max) <= 0) aligned = (0, _internationalized_date.minDate)(aligned, alignEnd((0, _internationalized_date.toCalendarDate)(max), duration, locale));
|
|
36
|
+
return aligned;
|
|
79
37
|
}
|
|
80
38
|
function constrainValue(date, minValue, maxValue) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if ("hour" in date) {
|
|
95
|
-
return date.set({
|
|
96
|
-
year: constrainedDateOnly.year,
|
|
97
|
-
month: constrainedDateOnly.month,
|
|
98
|
-
day: constrainedDateOnly.day
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return constrainedDateOnly;
|
|
39
|
+
const dateOnly = (0, _internationalized_date.toCalendarDate)(date);
|
|
40
|
+
const minOnly = minValue ? (0, _internationalized_date.toCalendarDate)(minValue) : void 0;
|
|
41
|
+
const maxOnly = maxValue ? (0, _internationalized_date.toCalendarDate)(maxValue) : void 0;
|
|
42
|
+
let constrainedDateOnly = dateOnly;
|
|
43
|
+
if (minOnly) constrainedDateOnly = (0, _internationalized_date.maxDate)(constrainedDateOnly, minOnly);
|
|
44
|
+
if (maxOnly) constrainedDateOnly = (0, _internationalized_date.minDate)(constrainedDateOnly, maxOnly);
|
|
45
|
+
if (constrainedDateOnly.compare(dateOnly) === 0) return date;
|
|
46
|
+
if ("hour" in date) return date.set({
|
|
47
|
+
year: constrainedDateOnly.year,
|
|
48
|
+
month: constrainedDateOnly.month,
|
|
49
|
+
day: constrainedDateOnly.day
|
|
50
|
+
});
|
|
51
|
+
return constrainedDateOnly;
|
|
102
52
|
}
|
|
103
53
|
function constrainSegments(date, minValue, maxValue) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) {
|
|
127
|
-
result = result.set({ day: maxOnly.day });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (result.compare(dateOnly) === 0) {
|
|
131
|
-
return date;
|
|
132
|
-
}
|
|
133
|
-
if ("hour" in date) {
|
|
134
|
-
return date.set({ year: result.year, month: result.month, day: result.day });
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
54
|
+
const dateOnly = (0, _internationalized_date.toCalendarDate)(date);
|
|
55
|
+
const minOnly = minValue ? (0, _internationalized_date.toCalendarDate)(minValue) : void 0;
|
|
56
|
+
const maxOnly = maxValue ? (0, _internationalized_date.toCalendarDate)(maxValue) : void 0;
|
|
57
|
+
let result = dateOnly;
|
|
58
|
+
if (minOnly && result.compare(minOnly) < 0) {
|
|
59
|
+
if (result.year < minOnly.year) result = result.set({ year: minOnly.year });
|
|
60
|
+
if (result.compare(minOnly) < 0 && result.month < minOnly.month) result = result.set({ month: minOnly.month });
|
|
61
|
+
if (result.compare(minOnly) < 0 && result.day < minOnly.day) result = result.set({ day: minOnly.day });
|
|
62
|
+
}
|
|
63
|
+
if (maxOnly && result.compare(maxOnly) > 0) {
|
|
64
|
+
if (result.year > maxOnly.year) result = result.set({ year: maxOnly.year });
|
|
65
|
+
if (result.compare(maxOnly) > 0 && result.month > maxOnly.month) result = result.set({ month: maxOnly.month });
|
|
66
|
+
if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) result = result.set({ day: maxOnly.day });
|
|
67
|
+
}
|
|
68
|
+
if (result.compare(dateOnly) === 0) return date;
|
|
69
|
+
if ("hour" in date) return date.set({
|
|
70
|
+
year: result.year,
|
|
71
|
+
month: result.month,
|
|
72
|
+
day: result.day
|
|
73
|
+
});
|
|
74
|
+
return result;
|
|
137
75
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
constrainStart,
|
|
145
|
-
constrainValue
|
|
146
|
-
});
|
|
76
|
+
exports.alignCenter = alignCenter;
|
|
77
|
+
exports.alignEnd = alignEnd;
|
|
78
|
+
exports.alignStart = alignStart;
|
|
79
|
+
exports.constrainSegments = constrainSegments;
|
|
80
|
+
exports.constrainStart = constrainStart;
|
|
81
|
+
exports.constrainValue = constrainValue;
|