@zag-js/date-utils 1.47.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/constrain.mjs
CHANGED
|
@@ -1,123 +1,72 @@
|
|
|
1
|
+
import { maxDate, minDate, startOfMonth, startOfWeek, startOfYear, toCalendarDate } from "@internationalized/date";
|
|
1
2
|
// src/constrain.ts
|
|
2
|
-
import {
|
|
3
|
-
maxDate,
|
|
4
|
-
minDate,
|
|
5
|
-
startOfMonth,
|
|
6
|
-
startOfWeek,
|
|
7
|
-
startOfYear,
|
|
8
|
-
toCalendarDate
|
|
9
|
-
} from "@internationalized/date";
|
|
10
3
|
function alignCenter(date, duration, locale, min, max) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const aligned = alignStart(date, duration, locale).subtract(halfDuration);
|
|
22
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
4
|
+
const halfDuration = {};
|
|
5
|
+
for (let prop in duration) {
|
|
6
|
+
const key = prop;
|
|
7
|
+
const value = duration[key];
|
|
8
|
+
if (value == null) continue;
|
|
9
|
+
halfDuration[key] = Math.floor(value / 2);
|
|
10
|
+
if (halfDuration[key] > 0 && value % 2 === 0) halfDuration[key]--;
|
|
11
|
+
}
|
|
12
|
+
return constrainStart(date, alignStart(date, duration, locale).subtract(halfDuration), duration, locale, min, max);
|
|
23
13
|
}
|
|
24
14
|
function alignStart(date, duration, locale, min, max) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} else if (duration.weeks) {
|
|
31
|
-
aligned = startOfWeek(date, locale);
|
|
32
|
-
}
|
|
33
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
15
|
+
let aligned = date;
|
|
16
|
+
if (duration.years) aligned = startOfYear(date);
|
|
17
|
+
else if (duration.months) aligned = startOfMonth(date);
|
|
18
|
+
else if (duration.weeks) aligned = startOfWeek(date, locale);
|
|
19
|
+
return constrainStart(date, aligned, duration, locale, min, max);
|
|
34
20
|
}
|
|
35
21
|
function alignEnd(date, duration, locale, min, max) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
d.months--;
|
|
43
|
-
} else if (d.years) {
|
|
44
|
-
d.years--;
|
|
45
|
-
}
|
|
46
|
-
let aligned = alignStart(date, duration, locale).subtract(d);
|
|
47
|
-
return constrainStart(date, aligned, duration, locale, min, max);
|
|
22
|
+
let d = { ...duration };
|
|
23
|
+
if (d.days) d.days--;
|
|
24
|
+
else if (d.weeks) d.weeks--;
|
|
25
|
+
else if (d.months) d.months--;
|
|
26
|
+
else if (d.years) d.years--;
|
|
27
|
+
return constrainStart(date, alignStart(date, duration, locale).subtract(d), duration, locale, min, max);
|
|
48
28
|
}
|
|
49
29
|
function constrainStart(date, aligned, duration, locale, min, max) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (max && date.compare(max) <= 0) {
|
|
54
|
-
aligned = minDate(aligned, alignEnd(toCalendarDate(max), duration, locale));
|
|
55
|
-
}
|
|
56
|
-
return aligned;
|
|
30
|
+
if (min && date.compare(min) >= 0) aligned = maxDate(aligned, alignStart(toCalendarDate(min), duration, locale));
|
|
31
|
+
if (max && date.compare(max) <= 0) aligned = minDate(aligned, alignEnd(toCalendarDate(max), duration, locale));
|
|
32
|
+
return aligned;
|
|
57
33
|
}
|
|
58
34
|
function constrainValue(date, minValue, maxValue) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if ("hour" in date) {
|
|
73
|
-
return date.set({
|
|
74
|
-
year: constrainedDateOnly.year,
|
|
75
|
-
month: constrainedDateOnly.month,
|
|
76
|
-
day: constrainedDateOnly.day
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return constrainedDateOnly;
|
|
35
|
+
const dateOnly = toCalendarDate(date);
|
|
36
|
+
const minOnly = minValue ? toCalendarDate(minValue) : void 0;
|
|
37
|
+
const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
|
|
38
|
+
let constrainedDateOnly = dateOnly;
|
|
39
|
+
if (minOnly) constrainedDateOnly = maxDate(constrainedDateOnly, minOnly);
|
|
40
|
+
if (maxOnly) constrainedDateOnly = minDate(constrainedDateOnly, maxOnly);
|
|
41
|
+
if (constrainedDateOnly.compare(dateOnly) === 0) return date;
|
|
42
|
+
if ("hour" in date) return date.set({
|
|
43
|
+
year: constrainedDateOnly.year,
|
|
44
|
+
month: constrainedDateOnly.month,
|
|
45
|
+
day: constrainedDateOnly.day
|
|
46
|
+
});
|
|
47
|
+
return constrainedDateOnly;
|
|
80
48
|
}
|
|
81
49
|
function constrainSegments(date, minValue, maxValue) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) {
|
|
105
|
-
result = result.set({ day: maxOnly.day });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (result.compare(dateOnly) === 0) {
|
|
109
|
-
return date;
|
|
110
|
-
}
|
|
111
|
-
if ("hour" in date) {
|
|
112
|
-
return date.set({ year: result.year, month: result.month, day: result.day });
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
50
|
+
const dateOnly = toCalendarDate(date);
|
|
51
|
+
const minOnly = minValue ? toCalendarDate(minValue) : void 0;
|
|
52
|
+
const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
|
|
53
|
+
let result = dateOnly;
|
|
54
|
+
if (minOnly && result.compare(minOnly) < 0) {
|
|
55
|
+
if (result.year < minOnly.year) result = result.set({ year: minOnly.year });
|
|
56
|
+
if (result.compare(minOnly) < 0 && result.month < minOnly.month) result = result.set({ month: minOnly.month });
|
|
57
|
+
if (result.compare(minOnly) < 0 && result.day < minOnly.day) result = result.set({ day: minOnly.day });
|
|
58
|
+
}
|
|
59
|
+
if (maxOnly && result.compare(maxOnly) > 0) {
|
|
60
|
+
if (result.year > maxOnly.year) result = result.set({ year: maxOnly.year });
|
|
61
|
+
if (result.compare(maxOnly) > 0 && result.month > maxOnly.month) result = result.set({ month: maxOnly.month });
|
|
62
|
+
if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) result = result.set({ day: maxOnly.day });
|
|
63
|
+
}
|
|
64
|
+
if (result.compare(dateOnly) === 0) return date;
|
|
65
|
+
if ("hour" in date) return date.set({
|
|
66
|
+
year: result.year,
|
|
67
|
+
month: result.month,
|
|
68
|
+
day: result.day
|
|
69
|
+
});
|
|
70
|
+
return result;
|
|
115
71
|
}
|
|
116
|
-
export {
|
|
117
|
-
alignCenter,
|
|
118
|
-
alignEnd,
|
|
119
|
-
alignStart,
|
|
120
|
-
constrainSegments,
|
|
121
|
-
constrainStart,
|
|
122
|
-
constrainValue
|
|
123
|
-
};
|
|
72
|
+
export { alignCenter, alignEnd, alignStart, constrainSegments, constrainStart, constrainValue };
|
package/dist/date-month.d.mts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
long: string;
|
|
12
|
-
narrow: string;
|
|
1
|
+
import { DateValue } from "@internationalized/date";
|
|
2
|
+
export declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
3
|
+
export declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
4
|
+
export declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
|
|
5
|
+
export declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
|
|
6
|
+
export declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
|
|
7
|
+
value: T;
|
|
8
|
+
short: string;
|
|
9
|
+
long: string;
|
|
10
|
+
narrow: string;
|
|
13
11
|
};
|
|
14
|
-
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
export declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
13
|
+
value: import("@internationalized/date").CalendarDate | import("@internationalized/date").CalendarDateTime | import("@internationalized/date").ZonedDateTime;
|
|
14
|
+
short: string;
|
|
15
|
+
long: string;
|
|
16
|
+
narrow: string;
|
|
19
17
|
}[];
|
|
20
|
-
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
|
|
21
|
-
declare function getWeekOfYear(date: DateValue, locale: string): number;
|
|
22
|
-
|
|
23
|
-
export { getDaysInWeek, getEndOfWeek, getMonthDays, getMonthNames, getStartOfWeek, getWeekDays, getWeekOfYear, getWeekdayFormats };
|
|
18
|
+
export declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
|
|
19
|
+
export declare function getWeekOfYear(date: DateValue, locale: string): number;
|
package/dist/date-month.d.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
long: string;
|
|
12
|
-
narrow: string;
|
|
1
|
+
import { DateValue } from "@internationalized/date";
|
|
2
|
+
export declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
3
|
+
export declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
4
|
+
export declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
|
|
5
|
+
export declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
|
|
6
|
+
export declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
|
|
7
|
+
value: T;
|
|
8
|
+
short: string;
|
|
9
|
+
long: string;
|
|
10
|
+
narrow: string;
|
|
13
11
|
};
|
|
14
|
-
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
export declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
13
|
+
value: import("@internationalized/date").CalendarDate | import("@internationalized/date").CalendarDateTime | import("@internationalized/date").ZonedDateTime;
|
|
14
|
+
short: string;
|
|
15
|
+
long: string;
|
|
16
|
+
narrow: string;
|
|
19
17
|
}[];
|
|
20
|
-
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
|
|
21
|
-
declare function getWeekOfYear(date: DateValue, locale: string): number;
|
|
22
|
-
|
|
23
|
-
export { getDaysInWeek, getEndOfWeek, getMonthDays, getMonthNames, getStartOfWeek, getWeekDays, getWeekOfYear, getWeekdayFormats };
|
|
18
|
+
export declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
|
|
19
|
+
export declare function getWeekOfYear(date: DateValue, locale: string): number;
|
package/dist/date-month.js
CHANGED
|
@@ -1,131 +1,122 @@
|
|
|
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/date-month.ts
|
|
21
|
-
var date_month_exports = {};
|
|
22
|
-
__export(date_month_exports, {
|
|
23
|
-
getDaysInWeek: () => getDaysInWeek,
|
|
24
|
-
getEndOfWeek: () => getEndOfWeek,
|
|
25
|
-
getMonthDays: () => getMonthDays,
|
|
26
|
-
getMonthNames: () => getMonthNames,
|
|
27
|
-
getStartOfWeek: () => getStartOfWeek,
|
|
28
|
-
getWeekDays: () => getWeekDays,
|
|
29
|
-
getWeekOfYear: () => getWeekOfYear,
|
|
30
|
-
getWeekdayFormats: () => getWeekdayFormats
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
5
|
+
let _internationalized_date = require("@internationalized/date");
|
|
6
|
+
// src/date-month.ts
|
|
7
|
+
const daysOfTheWeek = [
|
|
8
|
+
"sun",
|
|
9
|
+
"mon",
|
|
10
|
+
"tue",
|
|
11
|
+
"wed",
|
|
12
|
+
"thu",
|
|
13
|
+
"fri",
|
|
14
|
+
"sat"
|
|
15
|
+
];
|
|
35
16
|
function normalizeFirstDayOfWeek(firstDayOfWeek) {
|
|
36
|
-
|
|
17
|
+
return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
|
|
37
18
|
}
|
|
38
19
|
function getStartOfWeek(date, locale, firstDayOfWeek) {
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
21
|
+
return (0, _internationalized_date.startOfWeek)(date, locale, firstDay);
|
|
41
22
|
}
|
|
42
23
|
function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
25
|
+
return (0, _internationalized_date.endOfWeek)(date, locale, firstDay);
|
|
45
26
|
}
|
|
46
27
|
function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
const weekDate = from.add({ weeks: weekIndex });
|
|
29
|
+
const dates = [];
|
|
30
|
+
let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
|
|
31
|
+
while (dates.length < 7) {
|
|
32
|
+
dates.push(date);
|
|
33
|
+
let nextDate = date.add({ days: 1 });
|
|
34
|
+
if ((0, _internationalized_date.isSameDay)(date, nextDate)) break;
|
|
35
|
+
date = nextDate;
|
|
36
|
+
}
|
|
37
|
+
return dates;
|
|
57
38
|
}
|
|
58
39
|
function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
|
|
40
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
41
|
+
const monthWeeks = numOfWeeks ?? (0, _internationalized_date.getWeeksInMonth)(from, locale, firstDay);
|
|
42
|
+
return [...new Array(monthWeeks).keys()].map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
|
|
63
43
|
}
|
|
64
44
|
function getWeekdayFormats(locale, timeZone) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
45
|
+
const longFormat = new _internationalized_date.DateFormatter(locale, {
|
|
46
|
+
weekday: "long",
|
|
47
|
+
timeZone
|
|
48
|
+
});
|
|
49
|
+
const shortFormat = new _internationalized_date.DateFormatter(locale, {
|
|
50
|
+
weekday: "short",
|
|
51
|
+
timeZone
|
|
52
|
+
});
|
|
53
|
+
const narrowFormat = new _internationalized_date.DateFormatter(locale, {
|
|
54
|
+
weekday: "narrow",
|
|
55
|
+
timeZone
|
|
56
|
+
});
|
|
57
|
+
return (value) => {
|
|
58
|
+
const date = value instanceof Date ? value : value.toDate(timeZone);
|
|
59
|
+
return {
|
|
60
|
+
value,
|
|
61
|
+
short: shortFormat.format(date),
|
|
62
|
+
long: longFormat.format(date),
|
|
63
|
+
narrow: narrowFormat.format(date)
|
|
64
|
+
};
|
|
65
|
+
};
|
|
77
66
|
}
|
|
78
67
|
function getWeekDays(date, startOfWeekProp, timeZone, locale) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
|
|
69
|
+
const weeks = [...new Array(7).keys()];
|
|
70
|
+
const format = getWeekdayFormats(locale, timeZone);
|
|
71
|
+
return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
|
|
83
72
|
}
|
|
84
73
|
function getMonthNames(locale, format = "long", referenceDate) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
74
|
+
if (!referenceDate || referenceDate.calendar.identifier === "gregory" || referenceDate.calendar.identifier === "iso8601") {
|
|
75
|
+
const date = new Date(2021, 0, 1);
|
|
76
|
+
const monthNames = [];
|
|
77
|
+
for (let i = 0; i < 12; i++) {
|
|
78
|
+
monthNames.push(date.toLocaleString(locale, { month: format }));
|
|
79
|
+
date.setMonth(date.getMonth() + 1);
|
|
80
|
+
}
|
|
81
|
+
return monthNames;
|
|
82
|
+
}
|
|
83
|
+
const monthCount = referenceDate.calendar.getMonthsInYear(referenceDate);
|
|
84
|
+
const formatter = new _internationalized_date.DateFormatter(locale, {
|
|
85
|
+
month: format,
|
|
86
|
+
calendar: referenceDate.calendar.identifier
|
|
87
|
+
});
|
|
88
|
+
const monthNames = [];
|
|
89
|
+
for (let month = 1; month <= monthCount; month++) {
|
|
90
|
+
const d = referenceDate.set({ month });
|
|
91
|
+
monthNames.push(formatter.format(d.toDate("UTC")));
|
|
92
|
+
}
|
|
93
|
+
return monthNames;
|
|
105
94
|
}
|
|
106
95
|
function getWeekOfYear(date, locale) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
96
|
+
const mondayOfWeek = (0, _internationalized_date.startOfWeek)(date, locale, "mon");
|
|
97
|
+
const year = mondayOfWeek.year;
|
|
98
|
+
const jan4 = mondayOfWeek.set({
|
|
99
|
+
month: 1,
|
|
100
|
+
day: 4
|
|
101
|
+
});
|
|
102
|
+
const week1Monday = (0, _internationalized_date.startOfWeek)(jan4, locale, "mon");
|
|
103
|
+
const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
|
|
104
|
+
const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
|
|
105
|
+
if (julianMonday >= julianWeek1) return 1 + Math.floor((julianMonday - julianWeek1) / 7);
|
|
106
|
+
const prevJan4 = mondayOfWeek.set({
|
|
107
|
+
year: year - 1,
|
|
108
|
+
month: 1,
|
|
109
|
+
day: 4
|
|
110
|
+
});
|
|
111
|
+
const prevWeek1Monday = (0, _internationalized_date.startOfWeek)(prevJan4, locale, "mon");
|
|
112
|
+
const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
|
|
113
|
+
return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
|
|
120
114
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
getWeekOfYear,
|
|
130
|
-
getWeekdayFormats
|
|
131
|
-
});
|
|
115
|
+
exports.getDaysInWeek = getDaysInWeek;
|
|
116
|
+
exports.getEndOfWeek = getEndOfWeek;
|
|
117
|
+
exports.getMonthDays = getMonthDays;
|
|
118
|
+
exports.getMonthNames = getMonthNames;
|
|
119
|
+
exports.getStartOfWeek = getStartOfWeek;
|
|
120
|
+
exports.getWeekDays = getWeekDays;
|
|
121
|
+
exports.getWeekOfYear = getWeekOfYear;
|
|
122
|
+
exports.getWeekdayFormats = getWeekdayFormats;
|