@zag-js/date-utils 0.82.0 → 0.82.2
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/index.d.mts +14 -24
- package/dist/index.d.ts +14 -24
- package/dist/index.js +94 -141
- package/dist/index.mjs +93 -137
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -12,11 +12,11 @@ type DateAdjustFn = (options: {
|
|
|
12
12
|
focusedDate: DateValue;
|
|
13
13
|
endDate: DateValue;
|
|
14
14
|
};
|
|
15
|
+
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
15
16
|
|
|
16
17
|
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
|
|
17
18
|
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
|
|
18
19
|
|
|
19
|
-
declare function isTodayDate(date: DateValue, timeZone: string): boolean;
|
|
20
20
|
declare function isDateEqual(dateA: DateValue, dateB?: DateValue | null): boolean;
|
|
21
21
|
declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
22
22
|
declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
@@ -40,48 +40,39 @@ declare function getUnitDuration(duration: DateDuration): {
|
|
|
40
40
|
declare function getEndDate(startDate: DateValue, duration: DateDuration): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
41
41
|
|
|
42
42
|
declare function formatRange(startDate: DateValue, endDate: DateValue, formatter: DateFormatter, toString: (start: string, end: string) => string, timeZone: string): string;
|
|
43
|
-
|
|
44
43
|
declare function formatSelectedDate(startDate: DateValue, endDate: DateValue | null, locale: string, timeZone: string): string;
|
|
45
|
-
|
|
46
44
|
declare function formatVisibleRange(startDate: DateValue, endDate: DateValue | null, locale: string, timeZone: string): string;
|
|
47
45
|
|
|
48
46
|
declare function getDayFormatter(locale: string, timeZone: string): DateFormatter;
|
|
47
|
+
declare function getMonthFormatter(locale: string, timeZone: string): DateFormatter;
|
|
49
48
|
|
|
50
|
-
declare function
|
|
51
|
-
|
|
49
|
+
declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
50
|
+
declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
52
51
|
declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
|
|
53
|
-
declare function getCustomWeeksInMonth(from: DateValue, locale: string, firstDayOfWeek?: number): number;
|
|
54
52
|
declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
|
|
55
|
-
|
|
56
|
-
declare function getMonthFormatter(locale: string, timeZone: string): DateFormatter;
|
|
57
|
-
|
|
58
|
-
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"]): string[];
|
|
59
|
-
|
|
60
|
-
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
61
|
-
value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
62
|
-
short: string;
|
|
63
|
-
long: string;
|
|
64
|
-
narrow: string;
|
|
65
|
-
}[];
|
|
66
|
-
|
|
67
53
|
declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
|
|
68
54
|
value: T;
|
|
69
55
|
short: string;
|
|
70
56
|
long: string;
|
|
71
57
|
narrow: string;
|
|
72
58
|
};
|
|
59
|
+
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
60
|
+
value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
61
|
+
short: string;
|
|
62
|
+
long: string;
|
|
63
|
+
narrow: string;
|
|
64
|
+
}[];
|
|
65
|
+
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"]): string[];
|
|
73
66
|
|
|
74
67
|
interface YearsRange {
|
|
75
68
|
from: number;
|
|
76
69
|
to: number;
|
|
77
70
|
}
|
|
78
71
|
declare function getYearsRange(range: YearsRange): number[];
|
|
72
|
+
declare function normalizeYear(year: string | null | undefined): string | undefined;
|
|
73
|
+
declare function getDecadeRange(year: number): number[];
|
|
79
74
|
|
|
80
75
|
declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
|
|
81
|
-
declare function getNextDay(date: DateValue): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
82
|
-
declare function getPreviousDay(date: DateValue): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
83
|
-
declare function setMonth(date: DateValue, month: number): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
84
|
-
declare function setYear(date: DateValue, year: number): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
85
76
|
declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
86
77
|
declare function setDate(date: DateValue, startDate: DateValue, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue, maxValue: DateValue): DateValue | undefined;
|
|
87
78
|
declare function getPreviousAvailableDate(date: DateValue, minValue: DateValue, locale: string, isDateUnavailable?: DateAvailableFn): DateValue | undefined;
|
|
@@ -105,7 +96,6 @@ declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue
|
|
|
105
96
|
|
|
106
97
|
declare function parseDateString(date: string, locale: string, timeZone: string): DateValue | undefined;
|
|
107
98
|
|
|
108
|
-
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
109
99
|
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
|
110
100
|
|
|
111
|
-
export { type AdjustDateParams, type AdjustDateReturn, type DateAdjustFn, type DateGranularity, type DateRangePreset, type YearsRange, alignCenter, alignDate, alignEnd, alignStart, alignStartDate, constrainStart, constrainValue, formatRange, formatSelectedDate, formatVisibleRange, getAdjustedDateFn,
|
|
101
|
+
export { type AdjustDateParams, type AdjustDateReturn, type DateAdjustFn, type DateGranularity, type DateRangePreset, type YearsRange, alignCenter, alignDate, alignEnd, alignStart, alignStartDate, constrainStart, constrainValue, formatRange, formatSelectedDate, formatVisibleRange, getAdjustedDateFn, getDateRangePreset, getDayFormatter, getDaysInWeek, getDecadeRange, getEndDate, getEndOfWeek, getMonthDays, getMonthFormatter, getMonthNames, getNextPage, getNextRow, getNextSection, getPreviousAvailableDate, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart, getStartOfWeek, getTodayDate, getUnitDuration, getWeekDays, getWeekdayFormats, getYearsRange, isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,11 +12,11 @@ type DateAdjustFn = (options: {
|
|
|
12
12
|
focusedDate: DateValue;
|
|
13
13
|
endDate: DateValue;
|
|
14
14
|
};
|
|
15
|
+
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
15
16
|
|
|
16
17
|
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
|
|
17
18
|
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
|
|
18
19
|
|
|
19
|
-
declare function isTodayDate(date: DateValue, timeZone: string): boolean;
|
|
20
20
|
declare function isDateEqual(dateA: DateValue, dateB?: DateValue | null): boolean;
|
|
21
21
|
declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
22
22
|
declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
@@ -40,48 +40,39 @@ declare function getUnitDuration(duration: DateDuration): {
|
|
|
40
40
|
declare function getEndDate(startDate: DateValue, duration: DateDuration): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
41
41
|
|
|
42
42
|
declare function formatRange(startDate: DateValue, endDate: DateValue, formatter: DateFormatter, toString: (start: string, end: string) => string, timeZone: string): string;
|
|
43
|
-
|
|
44
43
|
declare function formatSelectedDate(startDate: DateValue, endDate: DateValue | null, locale: string, timeZone: string): string;
|
|
45
|
-
|
|
46
44
|
declare function formatVisibleRange(startDate: DateValue, endDate: DateValue | null, locale: string, timeZone: string): string;
|
|
47
45
|
|
|
48
46
|
declare function getDayFormatter(locale: string, timeZone: string): DateFormatter;
|
|
47
|
+
declare function getMonthFormatter(locale: string, timeZone: string): DateFormatter;
|
|
49
48
|
|
|
50
|
-
declare function
|
|
51
|
-
|
|
49
|
+
declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
50
|
+
declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
52
51
|
declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
|
|
53
|
-
declare function getCustomWeeksInMonth(from: DateValue, locale: string, firstDayOfWeek?: number): number;
|
|
54
52
|
declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
|
|
55
|
-
|
|
56
|
-
declare function getMonthFormatter(locale: string, timeZone: string): DateFormatter;
|
|
57
|
-
|
|
58
|
-
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"]): string[];
|
|
59
|
-
|
|
60
|
-
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
61
|
-
value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
62
|
-
short: string;
|
|
63
|
-
long: string;
|
|
64
|
-
narrow: string;
|
|
65
|
-
}[];
|
|
66
|
-
|
|
67
53
|
declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
|
|
68
54
|
value: T;
|
|
69
55
|
short: string;
|
|
70
56
|
long: string;
|
|
71
57
|
narrow: string;
|
|
72
58
|
};
|
|
59
|
+
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
60
|
+
value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
61
|
+
short: string;
|
|
62
|
+
long: string;
|
|
63
|
+
narrow: string;
|
|
64
|
+
}[];
|
|
65
|
+
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"]): string[];
|
|
73
66
|
|
|
74
67
|
interface YearsRange {
|
|
75
68
|
from: number;
|
|
76
69
|
to: number;
|
|
77
70
|
}
|
|
78
71
|
declare function getYearsRange(range: YearsRange): number[];
|
|
72
|
+
declare function normalizeYear(year: string | null | undefined): string | undefined;
|
|
73
|
+
declare function getDecadeRange(year: number): number[];
|
|
79
74
|
|
|
80
75
|
declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
|
|
81
|
-
declare function getNextDay(date: DateValue): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
82
|
-
declare function getPreviousDay(date: DateValue): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
83
|
-
declare function setMonth(date: DateValue, month: number): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
84
|
-
declare function setYear(date: DateValue, year: number): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
85
76
|
declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
86
77
|
declare function setDate(date: DateValue, startDate: DateValue, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue, maxValue: DateValue): DateValue | undefined;
|
|
87
78
|
declare function getPreviousAvailableDate(date: DateValue, minValue: DateValue, locale: string, isDateUnavailable?: DateAvailableFn): DateValue | undefined;
|
|
@@ -105,7 +96,6 @@ declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue
|
|
|
105
96
|
|
|
106
97
|
declare function parseDateString(date: string, locale: string, timeZone: string): DateValue | undefined;
|
|
107
98
|
|
|
108
|
-
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
109
99
|
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
|
110
100
|
|
|
111
|
-
export { type AdjustDateParams, type AdjustDateReturn, type DateAdjustFn, type DateGranularity, type DateRangePreset, type YearsRange, alignCenter, alignDate, alignEnd, alignStart, alignStartDate, constrainStart, constrainValue, formatRange, formatSelectedDate, formatVisibleRange, getAdjustedDateFn,
|
|
101
|
+
export { type AdjustDateParams, type AdjustDateReturn, type DateAdjustFn, type DateGranularity, type DateRangePreset, type YearsRange, alignCenter, alignDate, alignEnd, alignStart, alignStartDate, constrainStart, constrainValue, formatRange, formatSelectedDate, formatVisibleRange, getAdjustedDateFn, getDateRangePreset, getDayFormatter, getDaysInWeek, getDecadeRange, getEndDate, getEndOfWeek, getMonthDays, getMonthFormatter, getMonthNames, getNextPage, getNextRow, getNextSection, getPreviousAvailableDate, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart, getStartOfWeek, getTodayDate, getUnitDuration, getWeekDays, getWeekdayFormats, getYearsRange, isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
package/dist/index.js
CHANGED
|
@@ -82,9 +82,6 @@ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
|
|
|
82
82
|
}
|
|
83
83
|
return startDate;
|
|
84
84
|
}
|
|
85
|
-
function isTodayDate(date$1, timeZone) {
|
|
86
|
-
return date.isToday(date$1, timeZone);
|
|
87
|
-
}
|
|
88
85
|
function isDateEqual(dateA, dateB) {
|
|
89
86
|
return dateB != null && date.isSameDay(dateA, dateB);
|
|
90
87
|
}
|
|
@@ -118,22 +115,45 @@ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
|
|
|
118
115
|
// src/duration.ts
|
|
119
116
|
function getUnitDuration(duration) {
|
|
120
117
|
let clone = { ...duration };
|
|
121
|
-
for (let key in clone)
|
|
122
|
-
clone[key] = 1;
|
|
123
|
-
}
|
|
118
|
+
for (let key in clone) clone[key] = 1;
|
|
124
119
|
return clone;
|
|
125
120
|
}
|
|
126
121
|
function getEndDate(startDate, duration) {
|
|
127
122
|
let clone = { ...duration };
|
|
128
|
-
if (clone.days)
|
|
129
|
-
|
|
130
|
-
} else {
|
|
131
|
-
clone.days = -1;
|
|
132
|
-
}
|
|
123
|
+
if (clone.days) clone.days--;
|
|
124
|
+
else clone.days = -1;
|
|
133
125
|
return startDate.add(clone);
|
|
134
126
|
}
|
|
135
127
|
|
|
136
|
-
// src/format
|
|
128
|
+
// src/get-era-format.ts
|
|
129
|
+
function getEraFormat(date) {
|
|
130
|
+
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/formatter.ts
|
|
134
|
+
function getDayFormatter(locale, timeZone) {
|
|
135
|
+
const date$1 = date.toCalendarDateTime(date.today(timeZone));
|
|
136
|
+
return new date.DateFormatter(locale, {
|
|
137
|
+
weekday: "long",
|
|
138
|
+
month: "long",
|
|
139
|
+
year: "numeric",
|
|
140
|
+
day: "numeric",
|
|
141
|
+
era: getEraFormat(date$1),
|
|
142
|
+
timeZone
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function getMonthFormatter(locale, timeZone) {
|
|
146
|
+
const date$1 = date.toCalendarDate(date.today(timeZone));
|
|
147
|
+
return new date.DateFormatter(locale, {
|
|
148
|
+
month: "long",
|
|
149
|
+
year: "numeric",
|
|
150
|
+
era: getEraFormat(date$1),
|
|
151
|
+
calendar: date$1?.calendar.identifier,
|
|
152
|
+
timeZone
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/format.ts
|
|
137
157
|
function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
138
158
|
let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
139
159
|
let separatorIndex = -1;
|
|
@@ -156,26 +176,6 @@ function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
|
156
176
|
}
|
|
157
177
|
return toString(start, end);
|
|
158
178
|
}
|
|
159
|
-
|
|
160
|
-
// src/get-era-format.ts
|
|
161
|
-
function getEraFormat(date) {
|
|
162
|
-
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// src/get-day-formatter.ts
|
|
166
|
-
function getDayFormatter(locale, timeZone) {
|
|
167
|
-
const date$1 = date.toCalendarDateTime(date.today(timeZone));
|
|
168
|
-
return new date.DateFormatter(locale, {
|
|
169
|
-
weekday: "long",
|
|
170
|
-
month: "long",
|
|
171
|
-
year: "numeric",
|
|
172
|
-
day: "numeric",
|
|
173
|
-
era: getEraFormat(date$1),
|
|
174
|
-
timeZone
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/format-selected-date.ts
|
|
179
179
|
function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
180
180
|
let start = startDate;
|
|
181
181
|
let end = endDate ?? startDate;
|
|
@@ -185,18 +185,6 @@ function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
|
185
185
|
}
|
|
186
186
|
return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
|
|
187
187
|
}
|
|
188
|
-
function getMonthFormatter(locale, timeZone) {
|
|
189
|
-
const date$1 = date.toCalendarDate(date.today(timeZone));
|
|
190
|
-
return new date.DateFormatter(locale, {
|
|
191
|
-
month: "long",
|
|
192
|
-
year: "numeric",
|
|
193
|
-
era: getEraFormat(date$1),
|
|
194
|
-
calendar: date$1?.calendar.identifier,
|
|
195
|
-
timeZone
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// src/format-visible-range.ts
|
|
200
188
|
function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
201
189
|
const start = startDate;
|
|
202
190
|
const end = endDate ?? startDate;
|
|
@@ -213,27 +201,18 @@ function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
|
213
201
|
}
|
|
214
202
|
return "";
|
|
215
203
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const computedYear = year - year % 10 - 1;
|
|
220
|
-
const years = [];
|
|
221
|
-
for (let i = 0; i < 12; i += 1) {
|
|
222
|
-
const value = computedYear + i;
|
|
223
|
-
years.push(value);
|
|
224
|
-
}
|
|
225
|
-
return years;
|
|
204
|
+
var daysOfTheWeek = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
205
|
+
function normalizeFirstDayOfWeek(firstDayOfWeek) {
|
|
206
|
+
return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
|
|
226
207
|
}
|
|
227
208
|
function getStartOfWeek(date$1, locale, firstDayOfWeek) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return date.
|
|
209
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
210
|
+
return date.startOfWeek(date$1, locale, firstDay);
|
|
211
|
+
}
|
|
212
|
+
function getEndOfWeek(date$1, locale, firstDayOfWeek = 0) {
|
|
213
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
214
|
+
return date.endOfWeek(date$1, locale, firstDay);
|
|
234
215
|
}
|
|
235
|
-
|
|
236
|
-
// src/get-month-days.ts
|
|
237
216
|
function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
238
217
|
const weekDate = from.add({ weeks: weekIndex });
|
|
239
218
|
const dates = [];
|
|
@@ -241,36 +220,17 @@ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
|
241
220
|
while (dates.length < 7) {
|
|
242
221
|
dates.push(date$1);
|
|
243
222
|
let nextDate = date$1.add({ days: 1 });
|
|
244
|
-
if (date.isSameDay(date$1, nextDate))
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
223
|
+
if (date.isSameDay(date$1, nextDate)) break;
|
|
247
224
|
date$1 = nextDate;
|
|
248
225
|
}
|
|
249
226
|
return dates;
|
|
250
227
|
}
|
|
251
|
-
function getCustomWeeksInMonth(from, locale, firstDayOfWeek) {
|
|
252
|
-
if (firstDayOfWeek == null) {
|
|
253
|
-
return date.getWeeksInMonth(from, locale);
|
|
254
|
-
}
|
|
255
|
-
const paddingDays = (date.getDayOfWeek(date.startOfMonth(from), locale) - firstDayOfWeek + 7) % 7;
|
|
256
|
-
return Math.ceil((paddingDays + from.calendar.getDaysInMonth(from)) / 7);
|
|
257
|
-
}
|
|
258
228
|
function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
|
|
259
|
-
const
|
|
229
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
230
|
+
const monthWeeks = numOfWeeks ?? date.getWeeksInMonth(from, locale, firstDay);
|
|
260
231
|
const weeks = [...new Array(monthWeeks).keys()];
|
|
261
232
|
return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
|
|
262
233
|
}
|
|
263
|
-
|
|
264
|
-
// src/get-month-names.ts
|
|
265
|
-
function getMonthNames(locale, format = "long") {
|
|
266
|
-
const date = new Date(2021, 0, 1);
|
|
267
|
-
const monthNames = [];
|
|
268
|
-
for (let i = 0; i < 12; i++) {
|
|
269
|
-
monthNames.push(date.toLocaleString(locale, { month: format }));
|
|
270
|
-
date.setMonth(date.getMonth() + 1);
|
|
271
|
-
}
|
|
272
|
-
return monthNames;
|
|
273
|
-
}
|
|
274
234
|
function getWeekdayFormats(locale, timeZone) {
|
|
275
235
|
const longFormat = new date.DateFormatter(locale, { weekday: "long", timeZone });
|
|
276
236
|
const shortFormat = new date.DateFormatter(locale, { weekday: "short", timeZone });
|
|
@@ -285,38 +245,53 @@ function getWeekdayFormats(locale, timeZone) {
|
|
|
285
245
|
};
|
|
286
246
|
};
|
|
287
247
|
}
|
|
288
|
-
|
|
289
|
-
// src/get-week-days.ts
|
|
290
248
|
function getWeekDays(date, startOfWeekProp, timeZone, locale) {
|
|
291
249
|
const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
|
|
292
250
|
const weeks = [...new Array(7).keys()];
|
|
293
251
|
const format = getWeekdayFormats(locale, timeZone);
|
|
294
252
|
return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
|
|
295
253
|
}
|
|
254
|
+
function getMonthNames(locale, format = "long") {
|
|
255
|
+
const date = new Date(2021, 0, 1);
|
|
256
|
+
const monthNames = [];
|
|
257
|
+
for (let i = 0; i < 12; i++) {
|
|
258
|
+
monthNames.push(date.toLocaleString(locale, { month: format }));
|
|
259
|
+
date.setMonth(date.getMonth() + 1);
|
|
260
|
+
}
|
|
261
|
+
return monthNames;
|
|
262
|
+
}
|
|
296
263
|
|
|
297
|
-
// src/
|
|
264
|
+
// src/date-year.ts
|
|
298
265
|
function getYearsRange(range) {
|
|
299
266
|
const years = [];
|
|
300
|
-
for (let year = range.from; year <= range.to; year += 1)
|
|
301
|
-
|
|
267
|
+
for (let year = range.from; year <= range.to; year += 1) years.push(year);
|
|
268
|
+
return years;
|
|
269
|
+
}
|
|
270
|
+
var FUTURE_YEAR_COERCION = 10;
|
|
271
|
+
function normalizeYear(year) {
|
|
272
|
+
if (!year) return;
|
|
273
|
+
if (year.length === 3) return year.padEnd(4, "0");
|
|
274
|
+
if (year.length === 2) {
|
|
275
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
276
|
+
const currentCentury = Math.floor(currentYear / 100) * 100;
|
|
277
|
+
const twoDigitYear = parseInt(year.slice(-2), 10);
|
|
278
|
+
const fullYear = currentCentury + twoDigitYear;
|
|
279
|
+
return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
|
|
280
|
+
}
|
|
281
|
+
return year;
|
|
282
|
+
}
|
|
283
|
+
function getDecadeRange(year) {
|
|
284
|
+
const computedYear = year - year % 10 - 1;
|
|
285
|
+
const years = [];
|
|
286
|
+
for (let i = 0; i < 12; i += 1) {
|
|
287
|
+
const value = computedYear + i;
|
|
288
|
+
years.push(value);
|
|
302
289
|
}
|
|
303
290
|
return years;
|
|
304
291
|
}
|
|
305
292
|
function getTodayDate(timeZone) {
|
|
306
293
|
return date.today(timeZone ?? date.getLocalTimeZone());
|
|
307
294
|
}
|
|
308
|
-
function getNextDay(date) {
|
|
309
|
-
return date.add({ days: 1 });
|
|
310
|
-
}
|
|
311
|
-
function getPreviousDay(date) {
|
|
312
|
-
return date.subtract({ days: 1 });
|
|
313
|
-
}
|
|
314
|
-
function setMonth(date, month) {
|
|
315
|
-
return date.set({ month });
|
|
316
|
-
}
|
|
317
|
-
function setYear(date, year) {
|
|
318
|
-
return date.set({ year });
|
|
319
|
-
}
|
|
320
295
|
function setCalendar(date$1, calendar) {
|
|
321
296
|
return date.toCalendar(date.toCalendarDateTime(date$1), calendar);
|
|
322
297
|
}
|
|
@@ -508,25 +483,6 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
508
483
|
});
|
|
509
484
|
}
|
|
510
485
|
}
|
|
511
|
-
|
|
512
|
-
// src/normalize-year.ts
|
|
513
|
-
var FUTURE_YEAR_COERCION = 10;
|
|
514
|
-
function normalizeYear(year) {
|
|
515
|
-
if (!year) return;
|
|
516
|
-
if (year.length === 3) {
|
|
517
|
-
return year.padEnd(4, "0");
|
|
518
|
-
}
|
|
519
|
-
if (year.length === 2) {
|
|
520
|
-
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
521
|
-
const currentCentury = Math.floor(currentYear / 100) * 100;
|
|
522
|
-
const twoDigitYear = parseInt(year.slice(-2), 10);
|
|
523
|
-
const fullYear = currentCentury + twoDigitYear;
|
|
524
|
-
return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
|
|
525
|
-
}
|
|
526
|
-
return year;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// src/parse-date.ts
|
|
530
486
|
var isValidYear = (year) => year != null && year.length === 4;
|
|
531
487
|
var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
532
488
|
var isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
@@ -576,37 +532,37 @@ function extract(pattern, str) {
|
|
|
576
532
|
}, {});
|
|
577
533
|
}
|
|
578
534
|
function getDateRangePreset(preset, locale, timeZone) {
|
|
579
|
-
const
|
|
535
|
+
const today3 = date.now(timeZone);
|
|
580
536
|
switch (preset) {
|
|
581
537
|
case "thisWeek":
|
|
582
|
-
return [date.startOfWeek(
|
|
538
|
+
return [date.startOfWeek(today3, locale), date.endOfWeek(today3, locale)];
|
|
583
539
|
case "thisMonth":
|
|
584
|
-
return [date.startOfMonth(
|
|
540
|
+
return [date.startOfMonth(today3), today3];
|
|
585
541
|
case "thisQuarter":
|
|
586
|
-
return [date.startOfMonth(
|
|
542
|
+
return [date.startOfMonth(today3).add({ months: -today3.month % 3 }), today3];
|
|
587
543
|
case "thisYear":
|
|
588
|
-
return [date.startOfYear(
|
|
544
|
+
return [date.startOfYear(today3), today3];
|
|
589
545
|
case "last3Days":
|
|
590
|
-
return [
|
|
546
|
+
return [today3.add({ days: -2 }), today3];
|
|
591
547
|
case "last7Days":
|
|
592
|
-
return [
|
|
548
|
+
return [today3.add({ days: -6 }), today3];
|
|
593
549
|
case "last14Days":
|
|
594
|
-
return [
|
|
550
|
+
return [today3.add({ days: -13 }), today3];
|
|
595
551
|
case "last30Days":
|
|
596
|
-
return [
|
|
552
|
+
return [today3.add({ days: -29 }), today3];
|
|
597
553
|
case "last90Days":
|
|
598
|
-
return [
|
|
554
|
+
return [today3.add({ days: -89 }), today3];
|
|
599
555
|
case "lastMonth":
|
|
600
|
-
return [date.startOfMonth(
|
|
556
|
+
return [date.startOfMonth(today3.add({ months: -1 })), date.endOfMonth(today3.add({ months: -1 }))];
|
|
601
557
|
case "lastQuarter":
|
|
602
558
|
return [
|
|
603
|
-
date.startOfMonth(
|
|
604
|
-
date.endOfMonth(
|
|
559
|
+
date.startOfMonth(today3.add({ months: -today3.month % 3 - 3 })),
|
|
560
|
+
date.endOfMonth(today3.add({ months: -today3.month % 3 - 1 }))
|
|
605
561
|
];
|
|
606
562
|
case "lastWeek":
|
|
607
|
-
return [date.startOfWeek(
|
|
563
|
+
return [date.startOfWeek(today3, locale).add({ weeks: -1 }), date.endOfWeek(today3, locale).add({ weeks: -1 })];
|
|
608
564
|
case "lastYear":
|
|
609
|
-
return [date.startOfYear(
|
|
565
|
+
return [date.startOfYear(today3.add({ years: -1 })), date.endOfYear(today3.add({ years: -1 }))];
|
|
610
566
|
default:
|
|
611
567
|
throw new Error(`Invalid date range preset: ${preset}`);
|
|
612
568
|
}
|
|
@@ -623,26 +579,25 @@ exports.formatRange = formatRange;
|
|
|
623
579
|
exports.formatSelectedDate = formatSelectedDate;
|
|
624
580
|
exports.formatVisibleRange = formatVisibleRange;
|
|
625
581
|
exports.getAdjustedDateFn = getAdjustedDateFn;
|
|
626
|
-
exports.getCustomWeeksInMonth = getCustomWeeksInMonth;
|
|
627
582
|
exports.getDateRangePreset = getDateRangePreset;
|
|
628
583
|
exports.getDayFormatter = getDayFormatter;
|
|
629
584
|
exports.getDaysInWeek = getDaysInWeek;
|
|
630
585
|
exports.getDecadeRange = getDecadeRange;
|
|
631
586
|
exports.getEndDate = getEndDate;
|
|
587
|
+
exports.getEndOfWeek = getEndOfWeek;
|
|
632
588
|
exports.getMonthDays = getMonthDays;
|
|
633
589
|
exports.getMonthFormatter = getMonthFormatter;
|
|
634
590
|
exports.getMonthNames = getMonthNames;
|
|
635
|
-
exports.getNextDay = getNextDay;
|
|
636
591
|
exports.getNextPage = getNextPage;
|
|
637
592
|
exports.getNextRow = getNextRow;
|
|
638
593
|
exports.getNextSection = getNextSection;
|
|
639
594
|
exports.getPreviousAvailableDate = getPreviousAvailableDate;
|
|
640
|
-
exports.getPreviousDay = getPreviousDay;
|
|
641
595
|
exports.getPreviousPage = getPreviousPage;
|
|
642
596
|
exports.getPreviousRow = getPreviousRow;
|
|
643
597
|
exports.getPreviousSection = getPreviousSection;
|
|
644
598
|
exports.getSectionEnd = getSectionEnd;
|
|
645
599
|
exports.getSectionStart = getSectionStart;
|
|
600
|
+
exports.getStartOfWeek = getStartOfWeek;
|
|
646
601
|
exports.getTodayDate = getTodayDate;
|
|
647
602
|
exports.getUnitDuration = getUnitDuration;
|
|
648
603
|
exports.getWeekDays = getWeekDays;
|
|
@@ -655,9 +610,7 @@ exports.isDateOutsideVisibleRange = isDateOutsideVisibleRange;
|
|
|
655
610
|
exports.isDateUnavailable = isDateUnavailable;
|
|
656
611
|
exports.isNextVisibleRangeInvalid = isNextVisibleRangeInvalid;
|
|
657
612
|
exports.isPreviousVisibleRangeInvalid = isPreviousVisibleRangeInvalid;
|
|
658
|
-
exports.
|
|
613
|
+
exports.normalizeYear = normalizeYear;
|
|
659
614
|
exports.parseDateString = parseDateString;
|
|
660
615
|
exports.setCalendar = setCalendar;
|
|
661
616
|
exports.setDate = setDate;
|
|
662
|
-
exports.setMonth = setMonth;
|
|
663
|
-
exports.setYear = setYear;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { startOfYear, startOfMonth, startOfWeek, maxDate, toCalendarDate, minDate,
|
|
1
|
+
import { startOfYear, startOfMonth, startOfWeek, maxDate, toCalendarDate, minDate, isSameDay, toCalendarDateTime, today, DateFormatter, endOfMonth, endOfWeek, getWeeksInMonth, getLocalTimeZone, toCalendar, CalendarDate, now, endOfYear } from '@internationalized/date';
|
|
2
2
|
|
|
3
3
|
// src/constrain.ts
|
|
4
4
|
function alignCenter(date, duration, locale, min, max) {
|
|
@@ -80,9 +80,6 @@ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
|
|
|
80
80
|
}
|
|
81
81
|
return startDate;
|
|
82
82
|
}
|
|
83
|
-
function isTodayDate(date, timeZone) {
|
|
84
|
-
return isToday(date, timeZone);
|
|
85
|
-
}
|
|
86
83
|
function isDateEqual(dateA, dateB) {
|
|
87
84
|
return dateB != null && isSameDay(dateA, dateB);
|
|
88
85
|
}
|
|
@@ -116,22 +113,45 @@ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
|
|
|
116
113
|
// src/duration.ts
|
|
117
114
|
function getUnitDuration(duration) {
|
|
118
115
|
let clone = { ...duration };
|
|
119
|
-
for (let key in clone)
|
|
120
|
-
clone[key] = 1;
|
|
121
|
-
}
|
|
116
|
+
for (let key in clone) clone[key] = 1;
|
|
122
117
|
return clone;
|
|
123
118
|
}
|
|
124
119
|
function getEndDate(startDate, duration) {
|
|
125
120
|
let clone = { ...duration };
|
|
126
|
-
if (clone.days)
|
|
127
|
-
|
|
128
|
-
} else {
|
|
129
|
-
clone.days = -1;
|
|
130
|
-
}
|
|
121
|
+
if (clone.days) clone.days--;
|
|
122
|
+
else clone.days = -1;
|
|
131
123
|
return startDate.add(clone);
|
|
132
124
|
}
|
|
133
125
|
|
|
134
|
-
// src/format
|
|
126
|
+
// src/get-era-format.ts
|
|
127
|
+
function getEraFormat(date) {
|
|
128
|
+
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/formatter.ts
|
|
132
|
+
function getDayFormatter(locale, timeZone) {
|
|
133
|
+
const date = toCalendarDateTime(today(timeZone));
|
|
134
|
+
return new DateFormatter(locale, {
|
|
135
|
+
weekday: "long",
|
|
136
|
+
month: "long",
|
|
137
|
+
year: "numeric",
|
|
138
|
+
day: "numeric",
|
|
139
|
+
era: getEraFormat(date),
|
|
140
|
+
timeZone
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function getMonthFormatter(locale, timeZone) {
|
|
144
|
+
const date = toCalendarDate(today(timeZone));
|
|
145
|
+
return new DateFormatter(locale, {
|
|
146
|
+
month: "long",
|
|
147
|
+
year: "numeric",
|
|
148
|
+
era: getEraFormat(date),
|
|
149
|
+
calendar: date?.calendar.identifier,
|
|
150
|
+
timeZone
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/format.ts
|
|
135
155
|
function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
136
156
|
let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
137
157
|
let separatorIndex = -1;
|
|
@@ -154,26 +174,6 @@ function formatRange(startDate, endDate, formatter, toString, timeZone) {
|
|
|
154
174
|
}
|
|
155
175
|
return toString(start, end);
|
|
156
176
|
}
|
|
157
|
-
|
|
158
|
-
// src/get-era-format.ts
|
|
159
|
-
function getEraFormat(date) {
|
|
160
|
-
return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// src/get-day-formatter.ts
|
|
164
|
-
function getDayFormatter(locale, timeZone) {
|
|
165
|
-
const date = toCalendarDateTime(today(timeZone));
|
|
166
|
-
return new DateFormatter(locale, {
|
|
167
|
-
weekday: "long",
|
|
168
|
-
month: "long",
|
|
169
|
-
year: "numeric",
|
|
170
|
-
day: "numeric",
|
|
171
|
-
era: getEraFormat(date),
|
|
172
|
-
timeZone
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// src/format-selected-date.ts
|
|
177
177
|
function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
178
178
|
let start = startDate;
|
|
179
179
|
let end = endDate ?? startDate;
|
|
@@ -183,18 +183,6 @@ function formatSelectedDate(startDate, endDate, locale, timeZone) {
|
|
|
183
183
|
}
|
|
184
184
|
return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
|
|
185
185
|
}
|
|
186
|
-
function getMonthFormatter(locale, timeZone) {
|
|
187
|
-
const date = toCalendarDate(today(timeZone));
|
|
188
|
-
return new DateFormatter(locale, {
|
|
189
|
-
month: "long",
|
|
190
|
-
year: "numeric",
|
|
191
|
-
era: getEraFormat(date),
|
|
192
|
-
calendar: date?.calendar.identifier,
|
|
193
|
-
timeZone
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// src/format-visible-range.ts
|
|
198
186
|
function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
199
187
|
const start = startDate;
|
|
200
188
|
const end = endDate ?? startDate;
|
|
@@ -211,27 +199,18 @@ function formatVisibleRange(startDate, endDate, locale, timeZone) {
|
|
|
211
199
|
}
|
|
212
200
|
return "";
|
|
213
201
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const computedYear = year - year % 10 - 1;
|
|
218
|
-
const years = [];
|
|
219
|
-
for (let i = 0; i < 12; i += 1) {
|
|
220
|
-
const value = computedYear + i;
|
|
221
|
-
years.push(value);
|
|
222
|
-
}
|
|
223
|
-
return years;
|
|
202
|
+
var daysOfTheWeek = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
203
|
+
function normalizeFirstDayOfWeek(firstDayOfWeek) {
|
|
204
|
+
return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
|
|
224
205
|
}
|
|
225
206
|
function getStartOfWeek(date, locale, firstDayOfWeek) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return
|
|
207
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
208
|
+
return startOfWeek(date, locale, firstDay);
|
|
209
|
+
}
|
|
210
|
+
function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
|
|
211
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
212
|
+
return endOfWeek(date, locale, firstDay);
|
|
232
213
|
}
|
|
233
|
-
|
|
234
|
-
// src/get-month-days.ts
|
|
235
214
|
function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
236
215
|
const weekDate = from.add({ weeks: weekIndex });
|
|
237
216
|
const dates = [];
|
|
@@ -239,36 +218,17 @@ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
|
|
|
239
218
|
while (dates.length < 7) {
|
|
240
219
|
dates.push(date);
|
|
241
220
|
let nextDate = date.add({ days: 1 });
|
|
242
|
-
if (isSameDay(date, nextDate))
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
221
|
+
if (isSameDay(date, nextDate)) break;
|
|
245
222
|
date = nextDate;
|
|
246
223
|
}
|
|
247
224
|
return dates;
|
|
248
225
|
}
|
|
249
|
-
function getCustomWeeksInMonth(from, locale, firstDayOfWeek) {
|
|
250
|
-
if (firstDayOfWeek == null) {
|
|
251
|
-
return getWeeksInMonth(from, locale);
|
|
252
|
-
}
|
|
253
|
-
const paddingDays = (getDayOfWeek(startOfMonth(from), locale) - firstDayOfWeek + 7) % 7;
|
|
254
|
-
return Math.ceil((paddingDays + from.calendar.getDaysInMonth(from)) / 7);
|
|
255
|
-
}
|
|
256
226
|
function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
|
|
257
|
-
const
|
|
227
|
+
const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
228
|
+
const monthWeeks = numOfWeeks ?? getWeeksInMonth(from, locale, firstDay);
|
|
258
229
|
const weeks = [...new Array(monthWeeks).keys()];
|
|
259
230
|
return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
|
|
260
231
|
}
|
|
261
|
-
|
|
262
|
-
// src/get-month-names.ts
|
|
263
|
-
function getMonthNames(locale, format = "long") {
|
|
264
|
-
const date = new Date(2021, 0, 1);
|
|
265
|
-
const monthNames = [];
|
|
266
|
-
for (let i = 0; i < 12; i++) {
|
|
267
|
-
monthNames.push(date.toLocaleString(locale, { month: format }));
|
|
268
|
-
date.setMonth(date.getMonth() + 1);
|
|
269
|
-
}
|
|
270
|
-
return monthNames;
|
|
271
|
-
}
|
|
272
232
|
function getWeekdayFormats(locale, timeZone) {
|
|
273
233
|
const longFormat = new DateFormatter(locale, { weekday: "long", timeZone });
|
|
274
234
|
const shortFormat = new DateFormatter(locale, { weekday: "short", timeZone });
|
|
@@ -283,38 +243,53 @@ function getWeekdayFormats(locale, timeZone) {
|
|
|
283
243
|
};
|
|
284
244
|
};
|
|
285
245
|
}
|
|
286
|
-
|
|
287
|
-
// src/get-week-days.ts
|
|
288
246
|
function getWeekDays(date, startOfWeekProp, timeZone, locale) {
|
|
289
247
|
const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
|
|
290
248
|
const weeks = [...new Array(7).keys()];
|
|
291
249
|
const format = getWeekdayFormats(locale, timeZone);
|
|
292
250
|
return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
|
|
293
251
|
}
|
|
252
|
+
function getMonthNames(locale, format = "long") {
|
|
253
|
+
const date = new Date(2021, 0, 1);
|
|
254
|
+
const monthNames = [];
|
|
255
|
+
for (let i = 0; i < 12; i++) {
|
|
256
|
+
monthNames.push(date.toLocaleString(locale, { month: format }));
|
|
257
|
+
date.setMonth(date.getMonth() + 1);
|
|
258
|
+
}
|
|
259
|
+
return monthNames;
|
|
260
|
+
}
|
|
294
261
|
|
|
295
|
-
// src/
|
|
262
|
+
// src/date-year.ts
|
|
296
263
|
function getYearsRange(range) {
|
|
297
264
|
const years = [];
|
|
298
|
-
for (let year = range.from; year <= range.to; year += 1)
|
|
299
|
-
|
|
265
|
+
for (let year = range.from; year <= range.to; year += 1) years.push(year);
|
|
266
|
+
return years;
|
|
267
|
+
}
|
|
268
|
+
var FUTURE_YEAR_COERCION = 10;
|
|
269
|
+
function normalizeYear(year) {
|
|
270
|
+
if (!year) return;
|
|
271
|
+
if (year.length === 3) return year.padEnd(4, "0");
|
|
272
|
+
if (year.length === 2) {
|
|
273
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
274
|
+
const currentCentury = Math.floor(currentYear / 100) * 100;
|
|
275
|
+
const twoDigitYear = parseInt(year.slice(-2), 10);
|
|
276
|
+
const fullYear = currentCentury + twoDigitYear;
|
|
277
|
+
return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
|
|
278
|
+
}
|
|
279
|
+
return year;
|
|
280
|
+
}
|
|
281
|
+
function getDecadeRange(year) {
|
|
282
|
+
const computedYear = year - year % 10 - 1;
|
|
283
|
+
const years = [];
|
|
284
|
+
for (let i = 0; i < 12; i += 1) {
|
|
285
|
+
const value = computedYear + i;
|
|
286
|
+
years.push(value);
|
|
300
287
|
}
|
|
301
288
|
return years;
|
|
302
289
|
}
|
|
303
290
|
function getTodayDate(timeZone) {
|
|
304
291
|
return today(timeZone ?? getLocalTimeZone());
|
|
305
292
|
}
|
|
306
|
-
function getNextDay(date) {
|
|
307
|
-
return date.add({ days: 1 });
|
|
308
|
-
}
|
|
309
|
-
function getPreviousDay(date) {
|
|
310
|
-
return date.subtract({ days: 1 });
|
|
311
|
-
}
|
|
312
|
-
function setMonth(date, month) {
|
|
313
|
-
return date.set({ month });
|
|
314
|
-
}
|
|
315
|
-
function setYear(date, year) {
|
|
316
|
-
return date.set({ year });
|
|
317
|
-
}
|
|
318
293
|
function setCalendar(date, calendar) {
|
|
319
294
|
return toCalendar(toCalendarDateTime(date), calendar);
|
|
320
295
|
}
|
|
@@ -506,25 +481,6 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
|
|
|
506
481
|
});
|
|
507
482
|
}
|
|
508
483
|
}
|
|
509
|
-
|
|
510
|
-
// src/normalize-year.ts
|
|
511
|
-
var FUTURE_YEAR_COERCION = 10;
|
|
512
|
-
function normalizeYear(year) {
|
|
513
|
-
if (!year) return;
|
|
514
|
-
if (year.length === 3) {
|
|
515
|
-
return year.padEnd(4, "0");
|
|
516
|
-
}
|
|
517
|
-
if (year.length === 2) {
|
|
518
|
-
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
519
|
-
const currentCentury = Math.floor(currentYear / 100) * 100;
|
|
520
|
-
const twoDigitYear = parseInt(year.slice(-2), 10);
|
|
521
|
-
const fullYear = currentCentury + twoDigitYear;
|
|
522
|
-
return fullYear > currentYear + FUTURE_YEAR_COERCION ? (fullYear - 100).toString() : fullYear.toString();
|
|
523
|
-
}
|
|
524
|
-
return year;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// src/parse-date.ts
|
|
528
484
|
var isValidYear = (year) => year != null && year.length === 4;
|
|
529
485
|
var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
|
|
530
486
|
var isValidDay = (day) => day != null && parseFloat(day) <= 31;
|
|
@@ -574,40 +530,40 @@ function extract(pattern, str) {
|
|
|
574
530
|
}, {});
|
|
575
531
|
}
|
|
576
532
|
function getDateRangePreset(preset, locale, timeZone) {
|
|
577
|
-
const
|
|
533
|
+
const today3 = now(timeZone);
|
|
578
534
|
switch (preset) {
|
|
579
535
|
case "thisWeek":
|
|
580
|
-
return [startOfWeek(
|
|
536
|
+
return [startOfWeek(today3, locale), endOfWeek(today3, locale)];
|
|
581
537
|
case "thisMonth":
|
|
582
|
-
return [startOfMonth(
|
|
538
|
+
return [startOfMonth(today3), today3];
|
|
583
539
|
case "thisQuarter":
|
|
584
|
-
return [startOfMonth(
|
|
540
|
+
return [startOfMonth(today3).add({ months: -today3.month % 3 }), today3];
|
|
585
541
|
case "thisYear":
|
|
586
|
-
return [startOfYear(
|
|
542
|
+
return [startOfYear(today3), today3];
|
|
587
543
|
case "last3Days":
|
|
588
|
-
return [
|
|
544
|
+
return [today3.add({ days: -2 }), today3];
|
|
589
545
|
case "last7Days":
|
|
590
|
-
return [
|
|
546
|
+
return [today3.add({ days: -6 }), today3];
|
|
591
547
|
case "last14Days":
|
|
592
|
-
return [
|
|
548
|
+
return [today3.add({ days: -13 }), today3];
|
|
593
549
|
case "last30Days":
|
|
594
|
-
return [
|
|
550
|
+
return [today3.add({ days: -29 }), today3];
|
|
595
551
|
case "last90Days":
|
|
596
|
-
return [
|
|
552
|
+
return [today3.add({ days: -89 }), today3];
|
|
597
553
|
case "lastMonth":
|
|
598
|
-
return [startOfMonth(
|
|
554
|
+
return [startOfMonth(today3.add({ months: -1 })), endOfMonth(today3.add({ months: -1 }))];
|
|
599
555
|
case "lastQuarter":
|
|
600
556
|
return [
|
|
601
|
-
startOfMonth(
|
|
602
|
-
endOfMonth(
|
|
557
|
+
startOfMonth(today3.add({ months: -today3.month % 3 - 3 })),
|
|
558
|
+
endOfMonth(today3.add({ months: -today3.month % 3 - 1 }))
|
|
603
559
|
];
|
|
604
560
|
case "lastWeek":
|
|
605
|
-
return [startOfWeek(
|
|
561
|
+
return [startOfWeek(today3, locale).add({ weeks: -1 }), endOfWeek(today3, locale).add({ weeks: -1 })];
|
|
606
562
|
case "lastYear":
|
|
607
|
-
return [startOfYear(
|
|
563
|
+
return [startOfYear(today3.add({ years: -1 })), endOfYear(today3.add({ years: -1 }))];
|
|
608
564
|
default:
|
|
609
565
|
throw new Error(`Invalid date range preset: ${preset}`);
|
|
610
566
|
}
|
|
611
567
|
}
|
|
612
568
|
|
|
613
|
-
export { alignCenter, alignDate, alignEnd, alignStart, alignStartDate, constrainStart, constrainValue, formatRange, formatSelectedDate, formatVisibleRange, getAdjustedDateFn,
|
|
569
|
+
export { alignCenter, alignDate, alignEnd, alignStart, alignStartDate, constrainStart, constrainValue, formatRange, formatSelectedDate, formatVisibleRange, getAdjustedDateFn, getDateRangePreset, getDayFormatter, getDaysInWeek, getDecadeRange, getEndDate, getEndOfWeek, getMonthDays, getMonthFormatter, getMonthNames, getNextPage, getNextRow, getNextSection, getPreviousAvailableDate, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart, getStartOfWeek, getTodayDate, getUnitDuration, getWeekDays, getWeekdayFormats, getYearsRange, isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/date-utils",
|
|
3
|
-
"version": "0.82.
|
|
3
|
+
"version": "0.82.2",
|
|
4
4
|
"description": "Date utilities for zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@internationalized/date": ">=3.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@internationalized/date": "3.
|
|
30
|
+
"@internationalized/date": "3.7.0",
|
|
31
31
|
"clean-package": "2.2.0"
|
|
32
32
|
},
|
|
33
33
|
"module": "dist/index.mjs",
|