@zag-js/date-utils 0.0.0-dev-20230107115230
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/align.d.ts +7 -0
- package/dist/align.js +105 -0
- package/dist/align.mjs +9 -0
- package/dist/assertion.d.ts +13 -0
- package/dist/assertion.js +77 -0
- package/dist/assertion.mjs +20 -0
- package/dist/chunk-2DZ3KIVJ.mjs +73 -0
- package/dist/chunk-6NI2PIAA.mjs +27 -0
- package/dist/chunk-6XKXGQP6.mjs +32 -0
- package/dist/chunk-7JERMWT3.mjs +46 -0
- package/dist/chunk-C4U2N3JC.mjs +65 -0
- package/dist/chunk-DI2YG6VG.mjs +24 -0
- package/dist/chunk-ECAENYV6.mjs +19 -0
- package/dist/chunk-EXWX3KZT.mjs +64 -0
- package/dist/chunk-FJMTHABG.mjs +8 -0
- package/dist/chunk-HP2COJGP.mjs +76 -0
- package/dist/chunk-M4F23P2U.mjs +35 -0
- package/dist/chunk-TCPXGBJP.mjs +33 -0
- package/dist/chunk-TTJVXKJY.mjs +12 -0
- package/dist/chunk-VWVBJ5CB.mjs +110 -0
- package/dist/chunk-XHAL6X5Z.mjs +27 -0
- package/dist/chunk-ZSLC7OI2.mjs +22 -0
- package/dist/constrain.d.ts +10 -0
- package/dist/constrain.js +97 -0
- package/dist/constrain.mjs +14 -0
- package/dist/duration.d.ts +11 -0
- package/dist/duration.js +47 -0
- package/dist/duration.mjs +8 -0
- package/dist/format-range.d.ts +6 -0
- package/dist/format-range.js +51 -0
- package/dist/format-range.mjs +6 -0
- package/dist/format-selected-date.d.ts +6 -0
- package/dist/format-selected-date.js +86 -0
- package/dist/format-selected-date.mjs +9 -0
- package/dist/format-visible-range.d.ts +6 -0
- package/dist/format-visible-range.js +102 -0
- package/dist/format-visible-range.mjs +30 -0
- package/dist/get-era-format.d.ts +5 -0
- package/dist/get-era-format.js +32 -0
- package/dist/get-era-format.mjs +6 -0
- package/dist/get-formatter.d.ts +7 -0
- package/dist/get-formatter.js +61 -0
- package/dist/get-formatter.mjs +9 -0
- package/dist/get-month-dates.d.ts +5 -0
- package/dist/get-month-dates.js +65 -0
- package/dist/get-month-dates.mjs +7 -0
- package/dist/get-week-dates.d.ts +7 -0
- package/dist/get-week-dates.js +60 -0
- package/dist/get-week-dates.mjs +8 -0
- package/dist/get-year-range.d.ts +7 -0
- package/dist/get-year-range.js +36 -0
- package/dist/get-year-range.mjs +6 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +656 -0
- package/dist/index.mjs +120 -0
- package/dist/mutation.d.ts +13 -0
- package/dist/mutation.js +120 -0
- package/dist/mutation.mjs +22 -0
- package/dist/pagination.d.ts +25 -0
- package/dist/pagination.js +193 -0
- package/dist/pagination.mjs +22 -0
- package/dist/placeholder.d.ts +7 -0
- package/dist/placeholder.js +47 -0
- package/dist/placeholder.mjs +21 -0
- package/dist/segment-constants.d.ts +2 -0
- package/dist/segment-constants.js +52 -0
- package/dist/segment-constants.mjs +8 -0
- package/dist/segment-limit.d.ts +14 -0
- package/dist/segment-limit.js +97 -0
- package/dist/segment-limit.mjs +6 -0
- package/dist/segment-mutation.d.ts +8 -0
- package/dist/segment-mutation.js +89 -0
- package/dist/segment-mutation.mjs +8 -0
- package/dist/segment-parts.d.ts +25 -0
- package/dist/segment-parts.js +143 -0
- package/dist/segment-parts.mjs +37 -0
- package/dist/types-9f60d2f1.d.ts +61 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Chakra UI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @zag-js/date-utils
|
|
2
|
+
|
|
3
|
+
Date utilities for zag.js
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @zag-js/date-utils
|
|
9
|
+
# or
|
|
10
|
+
npm i @zag-js/date-utils
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Contribution
|
|
14
|
+
|
|
15
|
+
Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
|
|
16
|
+
|
|
17
|
+
## Licence
|
|
18
|
+
|
|
19
|
+
This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
|
package/dist/align.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CalendarDate } from '@internationalized/date';
|
|
2
|
+
import { D as DateContext, a as DateAlignment } from './types-9f60d2f1.js';
|
|
3
|
+
|
|
4
|
+
declare function alignDate(ctx: DateContext, date: CalendarDate, alignment: DateAlignment): CalendarDate;
|
|
5
|
+
declare function alignStartDate(ctx: DateContext, focusedDate: CalendarDate, startDate: CalendarDate, endDate: CalendarDate): CalendarDate;
|
|
6
|
+
|
|
7
|
+
export { alignDate, alignStartDate };
|
package/dist/align.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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/align.ts
|
|
21
|
+
var align_exports = {};
|
|
22
|
+
__export(align_exports, {
|
|
23
|
+
alignDate: () => alignDate,
|
|
24
|
+
alignStartDate: () => alignStartDate
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(align_exports);
|
|
27
|
+
|
|
28
|
+
// src/constrain.ts
|
|
29
|
+
var import_date = require("@internationalized/date");
|
|
30
|
+
function alignCenter(ctx, date) {
|
|
31
|
+
const { duration } = ctx;
|
|
32
|
+
let halfDuration = {};
|
|
33
|
+
for (let key in duration) {
|
|
34
|
+
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
35
|
+
if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
|
|
36
|
+
halfDuration[key]--;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let aligned = alignStart(ctx, date).subtract(halfDuration);
|
|
40
|
+
return constrainStart(ctx, date, aligned);
|
|
41
|
+
}
|
|
42
|
+
function alignStart(ctx, date) {
|
|
43
|
+
let { locale, duration } = ctx;
|
|
44
|
+
let aligned = date;
|
|
45
|
+
if (duration.years) {
|
|
46
|
+
aligned = (0, import_date.startOfYear)(date);
|
|
47
|
+
} else if (duration.months) {
|
|
48
|
+
aligned = (0, import_date.startOfMonth)(date);
|
|
49
|
+
} else if (duration.weeks) {
|
|
50
|
+
aligned = (0, import_date.startOfWeek)(date, locale);
|
|
51
|
+
}
|
|
52
|
+
return constrainStart(ctx, date, aligned);
|
|
53
|
+
}
|
|
54
|
+
function alignEnd(ctx, date) {
|
|
55
|
+
const { duration } = ctx;
|
|
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(ctx, date).subtract(d);
|
|
67
|
+
return constrainStart(ctx, date, aligned);
|
|
68
|
+
}
|
|
69
|
+
function constrainStart(ctx, date, aligned) {
|
|
70
|
+
let { min, max } = ctx;
|
|
71
|
+
if (min && date.compare(min) >= 0) {
|
|
72
|
+
aligned = (0, import_date.maxDate)(aligned, alignStart(ctx, (0, import_date.toCalendarDate)(min)));
|
|
73
|
+
}
|
|
74
|
+
if (max && date.compare(max) <= 0) {
|
|
75
|
+
aligned = (0, import_date.minDate)(aligned, alignEnd(ctx, (0, import_date.toCalendarDate)(max)));
|
|
76
|
+
}
|
|
77
|
+
return aligned;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/align.ts
|
|
81
|
+
function alignDate(ctx, date, alignment) {
|
|
82
|
+
switch (alignment) {
|
|
83
|
+
case "start":
|
|
84
|
+
return alignStart(ctx, date);
|
|
85
|
+
case "end":
|
|
86
|
+
return alignEnd(ctx, date);
|
|
87
|
+
case "center":
|
|
88
|
+
default:
|
|
89
|
+
return alignCenter(ctx, date);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function alignStartDate(ctx, focusedDate, startDate, endDate) {
|
|
93
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
94
|
+
return alignEnd(ctx, focusedDate);
|
|
95
|
+
}
|
|
96
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
97
|
+
return alignStart(ctx, focusedDate);
|
|
98
|
+
}
|
|
99
|
+
return startDate;
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
alignDate,
|
|
104
|
+
alignStartDate
|
|
105
|
+
});
|
package/dist/align.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CalendarDate, DateValue } from '@internationalized/date';
|
|
2
|
+
import { D as DateContext } from './types-9f60d2f1.js';
|
|
3
|
+
|
|
4
|
+
declare function isTodayDate(date: CalendarDate, timezone: string): boolean;
|
|
5
|
+
declare function isDateEqual(dateA: CalendarDate, dateB: CalendarDate | null | undefined): boolean;
|
|
6
|
+
declare function isDateInvalid(ctx: DateContext, date: DateValue): boolean;
|
|
7
|
+
declare function isDateDisabled(ctx: DateContext, date: DateValue, startDate: DateValue, endDate: DateValue): boolean;
|
|
8
|
+
declare function isDateUnavailable(ctx: DateContext, date: DateValue | null): boolean;
|
|
9
|
+
declare function isDateOutsideVisibleRange(date: CalendarDate, startDate: CalendarDate, endDate: CalendarDate): boolean;
|
|
10
|
+
declare function isPreviousVisibleRangeInvalid(ctx: DateContext, startDate: CalendarDate): boolean;
|
|
11
|
+
declare function isNextVisibleRangeInvalid(ctx: DateContext, endDate: CalendarDate): boolean;
|
|
12
|
+
|
|
13
|
+
export { isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, isTodayDate };
|
|
@@ -0,0 +1,77 @@
|
|
|
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/assertion.ts
|
|
21
|
+
var assertion_exports = {};
|
|
22
|
+
__export(assertion_exports, {
|
|
23
|
+
isDateDisabled: () => isDateDisabled,
|
|
24
|
+
isDateEqual: () => isDateEqual,
|
|
25
|
+
isDateInvalid: () => isDateInvalid,
|
|
26
|
+
isDateOutsideVisibleRange: () => isDateOutsideVisibleRange,
|
|
27
|
+
isDateUnavailable: () => isDateUnavailable,
|
|
28
|
+
isNextVisibleRangeInvalid: () => isNextVisibleRangeInvalid,
|
|
29
|
+
isPreviousVisibleRangeInvalid: () => isPreviousVisibleRangeInvalid,
|
|
30
|
+
isTodayDate: () => isTodayDate
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(assertion_exports);
|
|
33
|
+
var import_date = require("@internationalized/date");
|
|
34
|
+
function isTodayDate(date, timezone) {
|
|
35
|
+
return (0, import_date.isToday)(date, timezone);
|
|
36
|
+
}
|
|
37
|
+
function isDateEqual(dateA, dateB) {
|
|
38
|
+
return dateB != null && (0, import_date.isSameDay)(dateA, dateB);
|
|
39
|
+
}
|
|
40
|
+
function isDateInvalid(ctx, date) {
|
|
41
|
+
return ctx.min != null && date.compare(ctx.min) < 0 || ctx.max != null && date.compare(ctx.max) > 0;
|
|
42
|
+
}
|
|
43
|
+
function isDateDisabled(ctx, date, startDate, endDate) {
|
|
44
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(ctx, date);
|
|
45
|
+
}
|
|
46
|
+
function isDateUnavailable(ctx, date) {
|
|
47
|
+
var _a;
|
|
48
|
+
if (!date) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if ((_a = ctx.isUnavailable) == null ? void 0 : _a.call(ctx, date)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return isDateInvalid(ctx, date);
|
|
55
|
+
}
|
|
56
|
+
function isDateOutsideVisibleRange(date, startDate, endDate) {
|
|
57
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0;
|
|
58
|
+
}
|
|
59
|
+
function isPreviousVisibleRangeInvalid(ctx, startDate) {
|
|
60
|
+
let prev = startDate.subtract({ days: 1 });
|
|
61
|
+
return (0, import_date.isSameDay)(prev, startDate) || isDateInvalid(ctx, prev);
|
|
62
|
+
}
|
|
63
|
+
function isNextVisibleRangeInvalid(ctx, endDate) {
|
|
64
|
+
let next = endDate.add({ days: 1 });
|
|
65
|
+
return (0, import_date.isSameDay)(next, endDate) || isDateInvalid(ctx, next);
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
isDateDisabled,
|
|
70
|
+
isDateEqual,
|
|
71
|
+
isDateInvalid,
|
|
72
|
+
isDateOutsideVisibleRange,
|
|
73
|
+
isDateUnavailable,
|
|
74
|
+
isNextVisibleRangeInvalid,
|
|
75
|
+
isPreviousVisibleRangeInvalid,
|
|
76
|
+
isTodayDate
|
|
77
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isDateDisabled,
|
|
3
|
+
isDateEqual,
|
|
4
|
+
isDateInvalid,
|
|
5
|
+
isDateOutsideVisibleRange,
|
|
6
|
+
isDateUnavailable,
|
|
7
|
+
isNextVisibleRangeInvalid,
|
|
8
|
+
isPreviousVisibleRangeInvalid,
|
|
9
|
+
isTodayDate
|
|
10
|
+
} from "./chunk-7JERMWT3.mjs";
|
|
11
|
+
export {
|
|
12
|
+
isDateDisabled,
|
|
13
|
+
isDateEqual,
|
|
14
|
+
isDateInvalid,
|
|
15
|
+
isDateOutsideVisibleRange,
|
|
16
|
+
isDateUnavailable,
|
|
17
|
+
isNextVisibleRangeInvalid,
|
|
18
|
+
isPreviousVisibleRangeInvalid,
|
|
19
|
+
isTodayDate
|
|
20
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/segment-limit.ts
|
|
2
|
+
import { getMinimumDayInMonth, getMinimumMonthInYear } from "@internationalized/date";
|
|
3
|
+
function getSegmentLimits(date, type, options) {
|
|
4
|
+
switch (type) {
|
|
5
|
+
case "era": {
|
|
6
|
+
let eras = date.calendar.getEras();
|
|
7
|
+
return {
|
|
8
|
+
value: eras.indexOf(date.era),
|
|
9
|
+
min: 0,
|
|
10
|
+
max: eras.length - 1
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
case "year":
|
|
14
|
+
return {
|
|
15
|
+
value: date.year,
|
|
16
|
+
min: 1,
|
|
17
|
+
max: date.calendar.getYearsInEra(date)
|
|
18
|
+
};
|
|
19
|
+
case "month":
|
|
20
|
+
return {
|
|
21
|
+
value: date.month,
|
|
22
|
+
min: getMinimumMonthInYear(date),
|
|
23
|
+
max: date.calendar.getMonthsInYear(date)
|
|
24
|
+
};
|
|
25
|
+
case "day":
|
|
26
|
+
return {
|
|
27
|
+
value: date.day,
|
|
28
|
+
min: getMinimumDayInMonth(date),
|
|
29
|
+
max: date.calendar.getDaysInMonth(date)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if ("hour" in date) {
|
|
33
|
+
switch (type) {
|
|
34
|
+
case "dayPeriod":
|
|
35
|
+
return {
|
|
36
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
37
|
+
min: 0,
|
|
38
|
+
max: 12
|
|
39
|
+
};
|
|
40
|
+
case "hour":
|
|
41
|
+
if (options.hour12) {
|
|
42
|
+
let isPM = date.hour >= 12;
|
|
43
|
+
return {
|
|
44
|
+
value: date.hour,
|
|
45
|
+
min: isPM ? 12 : 0,
|
|
46
|
+
max: isPM ? 23 : 11
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
value: date.hour,
|
|
51
|
+
min: 0,
|
|
52
|
+
max: 23
|
|
53
|
+
};
|
|
54
|
+
case "minute":
|
|
55
|
+
return {
|
|
56
|
+
value: date.minute,
|
|
57
|
+
min: 0,
|
|
58
|
+
max: 59
|
|
59
|
+
};
|
|
60
|
+
case "second":
|
|
61
|
+
return {
|
|
62
|
+
value: date.second,
|
|
63
|
+
min: 0,
|
|
64
|
+
max: 59
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
getSegmentLimits
|
|
73
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/segment-constants.ts
|
|
2
|
+
var EDITABLE_SEGMENTS = {
|
|
3
|
+
year: true,
|
|
4
|
+
month: true,
|
|
5
|
+
day: true,
|
|
6
|
+
hour: true,
|
|
7
|
+
minute: true,
|
|
8
|
+
second: true,
|
|
9
|
+
dayPeriod: true,
|
|
10
|
+
era: true
|
|
11
|
+
};
|
|
12
|
+
var SEGMENT_PAGE_STEP = {
|
|
13
|
+
year: 5,
|
|
14
|
+
month: 2,
|
|
15
|
+
day: 7,
|
|
16
|
+
hour: 2,
|
|
17
|
+
minute: 15,
|
|
18
|
+
second: 15
|
|
19
|
+
};
|
|
20
|
+
function isSegmentEditable(segment) {
|
|
21
|
+
return EDITABLE_SEGMENTS[segment];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
SEGMENT_PAGE_STEP,
|
|
26
|
+
isSegmentEditable
|
|
27
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
alignCenter,
|
|
3
|
+
alignEnd,
|
|
4
|
+
alignStart
|
|
5
|
+
} from "./chunk-HP2COJGP.mjs";
|
|
6
|
+
|
|
7
|
+
// src/align.ts
|
|
8
|
+
function alignDate(ctx, date, alignment) {
|
|
9
|
+
switch (alignment) {
|
|
10
|
+
case "start":
|
|
11
|
+
return alignStart(ctx, date);
|
|
12
|
+
case "end":
|
|
13
|
+
return alignEnd(ctx, date);
|
|
14
|
+
case "center":
|
|
15
|
+
default:
|
|
16
|
+
return alignCenter(ctx, date);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function alignStartDate(ctx, focusedDate, startDate, endDate) {
|
|
20
|
+
if (focusedDate.compare(startDate) < 0) {
|
|
21
|
+
return alignEnd(ctx, focusedDate);
|
|
22
|
+
}
|
|
23
|
+
if (focusedDate.compare(endDate) > 0) {
|
|
24
|
+
return alignStart(ctx, focusedDate);
|
|
25
|
+
}
|
|
26
|
+
return startDate;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
alignDate,
|
|
31
|
+
alignStartDate
|
|
32
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/assertion.ts
|
|
2
|
+
import { isSameDay, isToday } from "@internationalized/date";
|
|
3
|
+
function isTodayDate(date, timezone) {
|
|
4
|
+
return isToday(date, timezone);
|
|
5
|
+
}
|
|
6
|
+
function isDateEqual(dateA, dateB) {
|
|
7
|
+
return dateB != null && isSameDay(dateA, dateB);
|
|
8
|
+
}
|
|
9
|
+
function isDateInvalid(ctx, date) {
|
|
10
|
+
return ctx.min != null && date.compare(ctx.min) < 0 || ctx.max != null && date.compare(ctx.max) > 0;
|
|
11
|
+
}
|
|
12
|
+
function isDateDisabled(ctx, date, startDate, endDate) {
|
|
13
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(ctx, date);
|
|
14
|
+
}
|
|
15
|
+
function isDateUnavailable(ctx, date) {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!date) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if ((_a = ctx.isUnavailable) == null ? void 0 : _a.call(ctx, date)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return isDateInvalid(ctx, date);
|
|
24
|
+
}
|
|
25
|
+
function isDateOutsideVisibleRange(date, startDate, endDate) {
|
|
26
|
+
return date.compare(startDate) < 0 || date.compare(endDate) > 0;
|
|
27
|
+
}
|
|
28
|
+
function isPreviousVisibleRangeInvalid(ctx, startDate) {
|
|
29
|
+
let prev = startDate.subtract({ days: 1 });
|
|
30
|
+
return isSameDay(prev, startDate) || isDateInvalid(ctx, prev);
|
|
31
|
+
}
|
|
32
|
+
function isNextVisibleRangeInvalid(ctx, endDate) {
|
|
33
|
+
let next = endDate.add({ days: 1 });
|
|
34
|
+
return isSameDay(next, endDate) || isDateInvalid(ctx, next);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
isTodayDate,
|
|
39
|
+
isDateEqual,
|
|
40
|
+
isDateInvalid,
|
|
41
|
+
isDateDisabled,
|
|
42
|
+
isDateUnavailable,
|
|
43
|
+
isDateOutsideVisibleRange,
|
|
44
|
+
isPreviousVisibleRangeInvalid,
|
|
45
|
+
isNextVisibleRangeInvalid
|
|
46
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isDateUnavailable
|
|
3
|
+
} from "./chunk-7JERMWT3.mjs";
|
|
4
|
+
import {
|
|
5
|
+
constrainValue
|
|
6
|
+
} from "./chunk-HP2COJGP.mjs";
|
|
7
|
+
|
|
8
|
+
// src/mutation.ts
|
|
9
|
+
import { GregorianCalendar, toCalendar, toCalendarDate, today } from "@internationalized/date";
|
|
10
|
+
function clampDate(ctx, date) {
|
|
11
|
+
return constrainValue(ctx, date);
|
|
12
|
+
}
|
|
13
|
+
function getTodayDate(timezone) {
|
|
14
|
+
return today(timezone);
|
|
15
|
+
}
|
|
16
|
+
function getNextDay(date) {
|
|
17
|
+
return date.add({ days: 1 });
|
|
18
|
+
}
|
|
19
|
+
function getPreviousDay(date) {
|
|
20
|
+
return date.subtract({ days: 1 });
|
|
21
|
+
}
|
|
22
|
+
function setMonth(date, month) {
|
|
23
|
+
return date.set({ month });
|
|
24
|
+
}
|
|
25
|
+
function setYear(date, year) {
|
|
26
|
+
return date.set({ year });
|
|
27
|
+
}
|
|
28
|
+
function setCalendar(date, calendar) {
|
|
29
|
+
return toCalendar(toCalendarDate(date), calendar);
|
|
30
|
+
}
|
|
31
|
+
function setDate(ctx, date, nextDate, startDate) {
|
|
32
|
+
let result;
|
|
33
|
+
result = clampDate(ctx, nextDate);
|
|
34
|
+
result = getPreviousAvailableDate(ctx, nextDate, startDate);
|
|
35
|
+
if (!result)
|
|
36
|
+
return;
|
|
37
|
+
result = toCalendar(result, (date == null ? void 0 : date.calendar) || new GregorianCalendar());
|
|
38
|
+
if (date && "hour" in date) {
|
|
39
|
+
return date.set(result);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function getPreviousAvailableDate(ctx, date, min) {
|
|
44
|
+
const minValue = min != null ? min : ctx.min;
|
|
45
|
+
if (!isDateUnavailable(ctx, date) || !minValue) {
|
|
46
|
+
return date;
|
|
47
|
+
}
|
|
48
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable(ctx, date)) {
|
|
49
|
+
date = date.subtract({ days: 1 });
|
|
50
|
+
}
|
|
51
|
+
if (date.compare(minValue) >= 0) {
|
|
52
|
+
return date;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
clampDate,
|
|
58
|
+
getTodayDate,
|
|
59
|
+
getNextDay,
|
|
60
|
+
getPreviousDay,
|
|
61
|
+
setMonth,
|
|
62
|
+
setYear,
|
|
63
|
+
setCalendar,
|
|
64
|
+
setDate
|
|
65
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDateFormatter
|
|
3
|
+
} from "./chunk-TCPXGBJP.mjs";
|
|
4
|
+
import {
|
|
5
|
+
formatRange
|
|
6
|
+
} from "./chunk-XHAL6X5Z.mjs";
|
|
7
|
+
|
|
8
|
+
// src/format-selected-date.ts
|
|
9
|
+
import { isSameDay } from "@internationalized/date";
|
|
10
|
+
function formatSelectedDate(ctx) {
|
|
11
|
+
const { start, end = start, timeZone } = ctx;
|
|
12
|
+
let formatter = getDateFormatter(ctx);
|
|
13
|
+
if (ctx.isSelectingRange || start == null || end == null) {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
if (isSameDay(start, end)) {
|
|
17
|
+
return formatter.format(start.toDate(timeZone));
|
|
18
|
+
}
|
|
19
|
+
return formatRange(ctx, formatter);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
formatSelectedDate
|
|
24
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDatesInWeek
|
|
3
|
+
} from "./chunk-M4F23P2U.mjs";
|
|
4
|
+
|
|
5
|
+
// src/get-month-dates.ts
|
|
6
|
+
import { getWeeksInMonth } from "@internationalized/date";
|
|
7
|
+
function getMonthDates(startDate, duration, locale) {
|
|
8
|
+
var _a;
|
|
9
|
+
let weeksInMonth = getWeeksInMonth(startDate, locale);
|
|
10
|
+
let numOfWeeks = (_a = duration.weeks) != null ? _a : weeksInMonth;
|
|
11
|
+
let weekArr = [...new Array(numOfWeeks).keys()];
|
|
12
|
+
return weekArr.map((index) => {
|
|
13
|
+
return getDatesInWeek(index, startDate, locale);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
getMonthDates
|
|
19
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/segment-mutation.ts
|
|
2
|
+
function addSegment(date, part, amount, options) {
|
|
3
|
+
switch (part) {
|
|
4
|
+
case "era":
|
|
5
|
+
case "year":
|
|
6
|
+
case "month":
|
|
7
|
+
case "day":
|
|
8
|
+
return date.cycle(part, amount, { round: part === "year" });
|
|
9
|
+
}
|
|
10
|
+
if ("hour" in date) {
|
|
11
|
+
switch (part) {
|
|
12
|
+
case "dayPeriod": {
|
|
13
|
+
let hours = date.hour;
|
|
14
|
+
let isPM = hours >= 12;
|
|
15
|
+
return date.set({ hour: isPM ? hours - 12 : hours + 12 });
|
|
16
|
+
}
|
|
17
|
+
case "hour":
|
|
18
|
+
case "minute":
|
|
19
|
+
case "second":
|
|
20
|
+
return date.cycle(part, amount, {
|
|
21
|
+
round: part !== "hour",
|
|
22
|
+
hourCycle: options.hour12 ? 12 : 24
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function setSegment(date, part, value, options) {
|
|
28
|
+
switch (part) {
|
|
29
|
+
case "day":
|
|
30
|
+
case "month":
|
|
31
|
+
case "year":
|
|
32
|
+
case "era":
|
|
33
|
+
return date.set({ [part]: value });
|
|
34
|
+
}
|
|
35
|
+
if ("hour" in date) {
|
|
36
|
+
switch (part) {
|
|
37
|
+
case "dayPeriod": {
|
|
38
|
+
let hours = date.hour;
|
|
39
|
+
let wasPM = hours >= 12;
|
|
40
|
+
let isPM = value >= 12;
|
|
41
|
+
return isPM === wasPM ? date : date.set({ hour: wasPM ? hours - 12 : hours + 12 });
|
|
42
|
+
}
|
|
43
|
+
case "hour":
|
|
44
|
+
if (options.hour12) {
|
|
45
|
+
let hours = date.hour;
|
|
46
|
+
let wasPM = hours >= 12;
|
|
47
|
+
if (!wasPM && value === 12) {
|
|
48
|
+
value = 0;
|
|
49
|
+
}
|
|
50
|
+
if (wasPM && value < 12) {
|
|
51
|
+
value += 12;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
case "minute":
|
|
55
|
+
case "second":
|
|
56
|
+
return date.set({ [part]: value });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
addSegment,
|
|
63
|
+
setSegment
|
|
64
|
+
};
|