@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/constrain.ts
|
|
2
|
+
import {
|
|
3
|
+
maxDate,
|
|
4
|
+
minDate,
|
|
5
|
+
startOfMonth,
|
|
6
|
+
startOfWeek,
|
|
7
|
+
startOfYear,
|
|
8
|
+
toCalendarDate
|
|
9
|
+
} from "@internationalized/date";
|
|
10
|
+
function alignCenter(ctx, date) {
|
|
11
|
+
const { duration } = ctx;
|
|
12
|
+
let halfDuration = {};
|
|
13
|
+
for (let key in duration) {
|
|
14
|
+
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
15
|
+
if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
|
|
16
|
+
halfDuration[key]--;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let aligned = alignStart(ctx, date).subtract(halfDuration);
|
|
20
|
+
return constrainStart(ctx, date, aligned);
|
|
21
|
+
}
|
|
22
|
+
function alignStart(ctx, date) {
|
|
23
|
+
let { locale, duration } = ctx;
|
|
24
|
+
let aligned = date;
|
|
25
|
+
if (duration.years) {
|
|
26
|
+
aligned = startOfYear(date);
|
|
27
|
+
} else if (duration.months) {
|
|
28
|
+
aligned = startOfMonth(date);
|
|
29
|
+
} else if (duration.weeks) {
|
|
30
|
+
aligned = startOfWeek(date, locale);
|
|
31
|
+
}
|
|
32
|
+
return constrainStart(ctx, date, aligned);
|
|
33
|
+
}
|
|
34
|
+
function alignEnd(ctx, date) {
|
|
35
|
+
const { duration } = ctx;
|
|
36
|
+
let d = { ...duration };
|
|
37
|
+
if (d.days) {
|
|
38
|
+
d.days--;
|
|
39
|
+
} else if (d.weeks) {
|
|
40
|
+
d.weeks--;
|
|
41
|
+
} else if (d.months) {
|
|
42
|
+
d.months--;
|
|
43
|
+
} else if (d.years) {
|
|
44
|
+
d.years--;
|
|
45
|
+
}
|
|
46
|
+
let aligned = alignStart(ctx, date).subtract(d);
|
|
47
|
+
return constrainStart(ctx, date, aligned);
|
|
48
|
+
}
|
|
49
|
+
function constrainValue(ctx, date) {
|
|
50
|
+
let { min, max } = ctx;
|
|
51
|
+
if (min) {
|
|
52
|
+
date = maxDate(date, toCalendarDate(min));
|
|
53
|
+
}
|
|
54
|
+
if (max) {
|
|
55
|
+
date = minDate(date, toCalendarDate(max));
|
|
56
|
+
}
|
|
57
|
+
return date;
|
|
58
|
+
}
|
|
59
|
+
function constrainStart(ctx, date, aligned) {
|
|
60
|
+
let { min, max } = ctx;
|
|
61
|
+
if (min && date.compare(min) >= 0) {
|
|
62
|
+
aligned = maxDate(aligned, alignStart(ctx, toCalendarDate(min)));
|
|
63
|
+
}
|
|
64
|
+
if (max && date.compare(max) <= 0) {
|
|
65
|
+
aligned = minDate(aligned, alignEnd(ctx, toCalendarDate(max)));
|
|
66
|
+
}
|
|
67
|
+
return aligned;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
alignCenter,
|
|
72
|
+
alignStart,
|
|
73
|
+
alignEnd,
|
|
74
|
+
constrainValue,
|
|
75
|
+
constrainStart
|
|
76
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/get-week-dates.ts
|
|
2
|
+
import { getDayOfWeek, isSameDay, startOfWeek, today } from "@internationalized/date";
|
|
3
|
+
function getDatesInWeek(weekIndex, fromDate, locale) {
|
|
4
|
+
let date = fromDate.add({ weeks: weekIndex });
|
|
5
|
+
let dates = [];
|
|
6
|
+
date = startOfWeek(date, locale);
|
|
7
|
+
let dayOfWeek = getDayOfWeek(date, locale);
|
|
8
|
+
for (let i = 0; i < dayOfWeek; i++) {
|
|
9
|
+
dates.push(null);
|
|
10
|
+
}
|
|
11
|
+
while (dates.length < 7) {
|
|
12
|
+
dates.push(date);
|
|
13
|
+
let nextDate = date.add({ days: 1 });
|
|
14
|
+
if (isSameDay(date, nextDate)) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
date = nextDate;
|
|
18
|
+
}
|
|
19
|
+
while (dates.length < 7) {
|
|
20
|
+
dates.push(null);
|
|
21
|
+
}
|
|
22
|
+
return dates;
|
|
23
|
+
}
|
|
24
|
+
function getWeekDates(timeZone, locale) {
|
|
25
|
+
let weekStart = startOfWeek(today(timeZone), locale);
|
|
26
|
+
let weekArr = [...new Array(7).keys()];
|
|
27
|
+
return weekArr.map((index) => {
|
|
28
|
+
return weekStart.add({ days: index }).toDate(timeZone);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
getDatesInWeek,
|
|
34
|
+
getWeekDates
|
|
35
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEraFormat
|
|
3
|
+
} from "./chunk-FJMTHABG.mjs";
|
|
4
|
+
|
|
5
|
+
// src/get-formatter.ts
|
|
6
|
+
function getDateFormatter(ctx) {
|
|
7
|
+
const { start, end = start, getDateFormatter: getDateFormatter2, timeZone } = ctx;
|
|
8
|
+
let era = getEraFormat(start) || getEraFormat(end);
|
|
9
|
+
return getDateFormatter2({
|
|
10
|
+
weekday: "long",
|
|
11
|
+
month: "long",
|
|
12
|
+
year: "numeric",
|
|
13
|
+
day: "numeric",
|
|
14
|
+
era,
|
|
15
|
+
timeZone
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function getMonthFormatter(ctx) {
|
|
19
|
+
const { start, end = start, getDateFormatter: getDateFormatter2, timeZone } = ctx;
|
|
20
|
+
let era = getEraFormat(start) || getEraFormat(end);
|
|
21
|
+
return getDateFormatter2({
|
|
22
|
+
month: "long",
|
|
23
|
+
year: "numeric",
|
|
24
|
+
era,
|
|
25
|
+
calendar: start == null ? void 0 : start.calendar.identifier,
|
|
26
|
+
timeZone
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
getDateFormatter,
|
|
32
|
+
getMonthFormatter
|
|
33
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
alignStart,
|
|
3
|
+
constrainStart,
|
|
4
|
+
constrainValue
|
|
5
|
+
} from "./chunk-HP2COJGP.mjs";
|
|
6
|
+
import {
|
|
7
|
+
getUnitDuration
|
|
8
|
+
} from "./chunk-ZSLC7OI2.mjs";
|
|
9
|
+
|
|
10
|
+
// src/pagination.ts
|
|
11
|
+
import { endOfMonth, endOfWeek, startOfMonth, startOfWeek } from "@internationalized/date";
|
|
12
|
+
function getNextPage(ctx, date, startDate) {
|
|
13
|
+
const start = startDate.add(ctx.duration);
|
|
14
|
+
return {
|
|
15
|
+
startDate: alignStart(ctx, constrainStart(ctx, date, start)),
|
|
16
|
+
focusedDate: constrainValue(ctx, date.add(ctx.duration))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getPreviousPage(ctx, date, startDate) {
|
|
20
|
+
const start = startDate.subtract(ctx.duration);
|
|
21
|
+
return {
|
|
22
|
+
startDate: alignStart(ctx, constrainStart(ctx, date, start)),
|
|
23
|
+
focusedDate: constrainValue(ctx, date.subtract(ctx.duration))
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getSectionStart(ctx, date, startDate) {
|
|
27
|
+
const d = ctx.duration;
|
|
28
|
+
if (d.days) {
|
|
29
|
+
return startDate;
|
|
30
|
+
}
|
|
31
|
+
if (d.weeks) {
|
|
32
|
+
return startOfWeek(date, ctx.locale);
|
|
33
|
+
}
|
|
34
|
+
if (d.months || d.years) {
|
|
35
|
+
return startOfMonth(date);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function getSectionEnd(ctx, date, endDate) {
|
|
39
|
+
const d = ctx.duration;
|
|
40
|
+
if (d.days) {
|
|
41
|
+
return endDate;
|
|
42
|
+
}
|
|
43
|
+
if (d.weeks) {
|
|
44
|
+
return endOfWeek(date, ctx.locale);
|
|
45
|
+
}
|
|
46
|
+
if (d.months || d.years) {
|
|
47
|
+
return endOfMonth(date);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function getNextSection(ctx, date, larger) {
|
|
51
|
+
const d = ctx.duration;
|
|
52
|
+
const unitDuration = getUnitDuration(ctx.duration);
|
|
53
|
+
if (!larger && !d.days) {
|
|
54
|
+
return date.add(unitDuration);
|
|
55
|
+
}
|
|
56
|
+
if (d.days) {
|
|
57
|
+
return date.add(d);
|
|
58
|
+
}
|
|
59
|
+
if (d.weeks) {
|
|
60
|
+
return date.add({ months: 1 });
|
|
61
|
+
}
|
|
62
|
+
if (d.months || d.years) {
|
|
63
|
+
return date.add({ years: 1 });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getPreviousSection(ctx, date, larger) {
|
|
67
|
+
const d = ctx.duration;
|
|
68
|
+
const unitDuration = getUnitDuration(ctx.duration);
|
|
69
|
+
if (!larger && !d.days) {
|
|
70
|
+
return date.subtract(unitDuration);
|
|
71
|
+
}
|
|
72
|
+
if (d.days) {
|
|
73
|
+
return date.subtract(ctx.duration);
|
|
74
|
+
}
|
|
75
|
+
if (d.weeks) {
|
|
76
|
+
return date.subtract({ months: 1 });
|
|
77
|
+
}
|
|
78
|
+
if (d.months || d.years) {
|
|
79
|
+
return date.subtract({ years: 1 });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getNextRow(ctx, date, startDate) {
|
|
83
|
+
const d = ctx.duration;
|
|
84
|
+
if (d.days) {
|
|
85
|
+
return getNextPage(ctx, date, startDate);
|
|
86
|
+
}
|
|
87
|
+
if (d.weeks || d.months || d.years) {
|
|
88
|
+
return date.add({ weeks: 1 });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function getPreviousRow(ctx, date, startDate) {
|
|
92
|
+
const d = ctx.duration;
|
|
93
|
+
if (d.days) {
|
|
94
|
+
return getPreviousPage(ctx, date, startDate);
|
|
95
|
+
}
|
|
96
|
+
if (d.weeks || d.months || d.years) {
|
|
97
|
+
return date.subtract({ weeks: 1 });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
getNextPage,
|
|
103
|
+
getPreviousPage,
|
|
104
|
+
getSectionStart,
|
|
105
|
+
getSectionEnd,
|
|
106
|
+
getNextSection,
|
|
107
|
+
getPreviousSection,
|
|
108
|
+
getNextRow,
|
|
109
|
+
getPreviousRow
|
|
110
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/format-range.ts
|
|
2
|
+
function formatRange(ctx, formatter) {
|
|
3
|
+
let parts = formatter.formatRangeToParts(ctx.start.toDate(ctx.timeZone), ctx.end.toDate(ctx.timeZone));
|
|
4
|
+
let separatorIndex = -1;
|
|
5
|
+
for (let i = 0; i < parts.length; i++) {
|
|
6
|
+
let part = parts[i];
|
|
7
|
+
if (part.source === "shared" && part.type === "literal") {
|
|
8
|
+
separatorIndex = i;
|
|
9
|
+
} else if (part.source === "endRange") {
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
let start = "";
|
|
14
|
+
let end = "";
|
|
15
|
+
for (let i = 0; i < parts.length; i++) {
|
|
16
|
+
if (i < separatorIndex) {
|
|
17
|
+
start += parts[i].value;
|
|
18
|
+
} else if (i > separatorIndex) {
|
|
19
|
+
end += parts[i].value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return ctx.toString(start, end);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
formatRange
|
|
27
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/duration.ts
|
|
2
|
+
function getUnitDuration(duration) {
|
|
3
|
+
let d = { ...duration };
|
|
4
|
+
for (let key in d) {
|
|
5
|
+
d[key] = 1;
|
|
6
|
+
}
|
|
7
|
+
return d;
|
|
8
|
+
}
|
|
9
|
+
function getEndDate(startDate, duration) {
|
|
10
|
+
let d = { ...duration };
|
|
11
|
+
if (d.days) {
|
|
12
|
+
d.days--;
|
|
13
|
+
} else {
|
|
14
|
+
d.days = -1;
|
|
15
|
+
}
|
|
16
|
+
return startDate.add(d);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
getUnitDuration,
|
|
21
|
+
getEndDate
|
|
22
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CalendarDate } from '@internationalized/date';
|
|
2
|
+
import { D as DateContext } from './types-9f60d2f1.js';
|
|
3
|
+
|
|
4
|
+
declare function alignCenter(ctx: DateContext, date: CalendarDate): CalendarDate;
|
|
5
|
+
declare function alignStart(ctx: DateContext, date: CalendarDate): CalendarDate;
|
|
6
|
+
declare function alignEnd(ctx: DateContext, date: CalendarDate): CalendarDate;
|
|
7
|
+
declare function constrainValue(ctx: DateContext, date: CalendarDate): CalendarDate;
|
|
8
|
+
declare function constrainStart(ctx: DateContext, date: CalendarDate, aligned: CalendarDate): CalendarDate;
|
|
9
|
+
|
|
10
|
+
export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue };
|
|
@@ -0,0 +1,97 @@
|
|
|
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/constrain.ts
|
|
21
|
+
var constrain_exports = {};
|
|
22
|
+
__export(constrain_exports, {
|
|
23
|
+
alignCenter: () => alignCenter,
|
|
24
|
+
alignEnd: () => alignEnd,
|
|
25
|
+
alignStart: () => alignStart,
|
|
26
|
+
constrainStart: () => constrainStart,
|
|
27
|
+
constrainValue: () => constrainValue
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(constrain_exports);
|
|
30
|
+
var import_date = require("@internationalized/date");
|
|
31
|
+
function alignCenter(ctx, date) {
|
|
32
|
+
const { duration } = ctx;
|
|
33
|
+
let halfDuration = {};
|
|
34
|
+
for (let key in duration) {
|
|
35
|
+
halfDuration[key] = Math.floor(duration[key] / 2);
|
|
36
|
+
if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
|
|
37
|
+
halfDuration[key]--;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let aligned = alignStart(ctx, date).subtract(halfDuration);
|
|
41
|
+
return constrainStart(ctx, date, aligned);
|
|
42
|
+
}
|
|
43
|
+
function alignStart(ctx, date) {
|
|
44
|
+
let { locale, duration } = ctx;
|
|
45
|
+
let aligned = date;
|
|
46
|
+
if (duration.years) {
|
|
47
|
+
aligned = (0, import_date.startOfYear)(date);
|
|
48
|
+
} else if (duration.months) {
|
|
49
|
+
aligned = (0, import_date.startOfMonth)(date);
|
|
50
|
+
} else if (duration.weeks) {
|
|
51
|
+
aligned = (0, import_date.startOfWeek)(date, locale);
|
|
52
|
+
}
|
|
53
|
+
return constrainStart(ctx, date, aligned);
|
|
54
|
+
}
|
|
55
|
+
function alignEnd(ctx, date) {
|
|
56
|
+
const { duration } = ctx;
|
|
57
|
+
let d = { ...duration };
|
|
58
|
+
if (d.days) {
|
|
59
|
+
d.days--;
|
|
60
|
+
} else if (d.weeks) {
|
|
61
|
+
d.weeks--;
|
|
62
|
+
} else if (d.months) {
|
|
63
|
+
d.months--;
|
|
64
|
+
} else if (d.years) {
|
|
65
|
+
d.years--;
|
|
66
|
+
}
|
|
67
|
+
let aligned = alignStart(ctx, date).subtract(d);
|
|
68
|
+
return constrainStart(ctx, date, aligned);
|
|
69
|
+
}
|
|
70
|
+
function constrainValue(ctx, date) {
|
|
71
|
+
let { min, max } = ctx;
|
|
72
|
+
if (min) {
|
|
73
|
+
date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(min));
|
|
74
|
+
}
|
|
75
|
+
if (max) {
|
|
76
|
+
date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(max));
|
|
77
|
+
}
|
|
78
|
+
return date;
|
|
79
|
+
}
|
|
80
|
+
function constrainStart(ctx, date, aligned) {
|
|
81
|
+
let { min, max } = ctx;
|
|
82
|
+
if (min && date.compare(min) >= 0) {
|
|
83
|
+
aligned = (0, import_date.maxDate)(aligned, alignStart(ctx, (0, import_date.toCalendarDate)(min)));
|
|
84
|
+
}
|
|
85
|
+
if (max && date.compare(max) <= 0) {
|
|
86
|
+
aligned = (0, import_date.minDate)(aligned, alignEnd(ctx, (0, import_date.toCalendarDate)(max)));
|
|
87
|
+
}
|
|
88
|
+
return aligned;
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
alignCenter,
|
|
93
|
+
alignEnd,
|
|
94
|
+
alignStart,
|
|
95
|
+
constrainStart,
|
|
96
|
+
constrainValue
|
|
97
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DateDuration, CalendarDate } from '@internationalized/date';
|
|
2
|
+
|
|
3
|
+
declare function getUnitDuration(duration: DateDuration): {
|
|
4
|
+
years?: number | undefined;
|
|
5
|
+
months?: number | undefined;
|
|
6
|
+
weeks?: number | undefined;
|
|
7
|
+
days?: number | undefined;
|
|
8
|
+
};
|
|
9
|
+
declare function getEndDate(startDate: CalendarDate, duration: DateDuration): CalendarDate;
|
|
10
|
+
|
|
11
|
+
export { getEndDate, getUnitDuration };
|
package/dist/duration.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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/duration.ts
|
|
21
|
+
var duration_exports = {};
|
|
22
|
+
__export(duration_exports, {
|
|
23
|
+
getEndDate: () => getEndDate,
|
|
24
|
+
getUnitDuration: () => getUnitDuration
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(duration_exports);
|
|
27
|
+
function getUnitDuration(duration) {
|
|
28
|
+
let d = { ...duration };
|
|
29
|
+
for (let key in d) {
|
|
30
|
+
d[key] = 1;
|
|
31
|
+
}
|
|
32
|
+
return d;
|
|
33
|
+
}
|
|
34
|
+
function getEndDate(startDate, duration) {
|
|
35
|
+
let d = { ...duration };
|
|
36
|
+
if (d.days) {
|
|
37
|
+
d.days--;
|
|
38
|
+
} else {
|
|
39
|
+
d.days = -1;
|
|
40
|
+
}
|
|
41
|
+
return startDate.add(d);
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
getEndDate,
|
|
46
|
+
getUnitDuration
|
|
47
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
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/format-range.ts
|
|
21
|
+
var format_range_exports = {};
|
|
22
|
+
__export(format_range_exports, {
|
|
23
|
+
formatRange: () => formatRange
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(format_range_exports);
|
|
26
|
+
function formatRange(ctx, formatter) {
|
|
27
|
+
let parts = formatter.formatRangeToParts(ctx.start.toDate(ctx.timeZone), ctx.end.toDate(ctx.timeZone));
|
|
28
|
+
let separatorIndex = -1;
|
|
29
|
+
for (let i = 0; i < parts.length; i++) {
|
|
30
|
+
let part = parts[i];
|
|
31
|
+
if (part.source === "shared" && part.type === "literal") {
|
|
32
|
+
separatorIndex = i;
|
|
33
|
+
} else if (part.source === "endRange") {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let start = "";
|
|
38
|
+
let end = "";
|
|
39
|
+
for (let i = 0; i < parts.length; i++) {
|
|
40
|
+
if (i < separatorIndex) {
|
|
41
|
+
start += parts[i].value;
|
|
42
|
+
} else if (i > separatorIndex) {
|
|
43
|
+
end += parts[i].value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return ctx.toString(start, end);
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
formatRange
|
|
51
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
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/format-selected-date.ts
|
|
21
|
+
var format_selected_date_exports = {};
|
|
22
|
+
__export(format_selected_date_exports, {
|
|
23
|
+
formatSelectedDate: () => formatSelectedDate
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(format_selected_date_exports);
|
|
26
|
+
var import_date = require("@internationalized/date");
|
|
27
|
+
|
|
28
|
+
// src/format-range.ts
|
|
29
|
+
function formatRange(ctx, formatter) {
|
|
30
|
+
let parts = formatter.formatRangeToParts(ctx.start.toDate(ctx.timeZone), ctx.end.toDate(ctx.timeZone));
|
|
31
|
+
let separatorIndex = -1;
|
|
32
|
+
for (let i = 0; i < parts.length; i++) {
|
|
33
|
+
let part = parts[i];
|
|
34
|
+
if (part.source === "shared" && part.type === "literal") {
|
|
35
|
+
separatorIndex = i;
|
|
36
|
+
} else if (part.source === "endRange") {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let start = "";
|
|
41
|
+
let end = "";
|
|
42
|
+
for (let i = 0; i < parts.length; i++) {
|
|
43
|
+
if (i < separatorIndex) {
|
|
44
|
+
start += parts[i].value;
|
|
45
|
+
} else if (i > separatorIndex) {
|
|
46
|
+
end += parts[i].value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return ctx.toString(start, end);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/get-era-format.ts
|
|
53
|
+
function getEraFormat(date) {
|
|
54
|
+
return (date == null ? void 0 : date.calendar.identifier) === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/get-formatter.ts
|
|
58
|
+
function getDateFormatter(ctx) {
|
|
59
|
+
const { start, end = start, getDateFormatter: getDateFormatter2, timeZone } = ctx;
|
|
60
|
+
let era = getEraFormat(start) || getEraFormat(end);
|
|
61
|
+
return getDateFormatter2({
|
|
62
|
+
weekday: "long",
|
|
63
|
+
month: "long",
|
|
64
|
+
year: "numeric",
|
|
65
|
+
day: "numeric",
|
|
66
|
+
era,
|
|
67
|
+
timeZone
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/format-selected-date.ts
|
|
72
|
+
function formatSelectedDate(ctx) {
|
|
73
|
+
const { start, end = start, timeZone } = ctx;
|
|
74
|
+
let formatter = getDateFormatter(ctx);
|
|
75
|
+
if (ctx.isSelectingRange || start == null || end == null) {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
if ((0, import_date.isSameDay)(start, end)) {
|
|
79
|
+
return formatter.format(start.toDate(timeZone));
|
|
80
|
+
}
|
|
81
|
+
return formatRange(ctx, formatter);
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
formatSelectedDate
|
|
86
|
+
});
|