@zag-js/date-utils 1.33.0 → 1.34.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/index.d.mts +21 -19
- package/dist/index.d.ts +21 -19
- package/dist/index.js +36 -7
- package/dist/index.mjs +35 -7
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
-
import {
|
|
2
|
+
import { CalendarDate, CalendarDateTime, ZonedDateTime, DateDuration, DateValue as DateValue$1, DateFormatter, Calendar } from '@internationalized/date';
|
|
3
3
|
|
|
4
|
+
type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
|
|
4
5
|
type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
5
6
|
type DateAlignment = "start" | "end" | "center";
|
|
6
7
|
type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
@@ -14,8 +15,8 @@ type DateAdjustFn = (options: {
|
|
|
14
15
|
};
|
|
15
16
|
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
16
17
|
|
|
17
|
-
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
|
|
18
|
-
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined):
|
|
18
|
+
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
|
|
19
|
+
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
19
20
|
|
|
20
21
|
declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
|
|
21
22
|
declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
@@ -23,11 +24,11 @@ declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | nul
|
|
|
23
24
|
declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
24
25
|
declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
25
26
|
|
|
26
|
-
declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
27
|
-
declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
28
|
-
declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
29
|
-
declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
30
|
-
declare function constrainValue(date:
|
|
27
|
+
declare function alignCenter(date: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
28
|
+
declare function alignStart(date: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
29
|
+
declare function alignEnd(date: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
30
|
+
declare function constrainStart(date: DateValue$1, aligned: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
31
|
+
declare function constrainValue<T extends DateValue$1>(date: T, minValue?: DateValue$1, maxValue?: DateValue$1): T;
|
|
31
32
|
|
|
32
33
|
declare function getUnitDuration(duration: DateDuration): {
|
|
33
34
|
years?: number;
|
|
@@ -44,23 +45,24 @@ declare function formatVisibleRange(startDate: DateValue, endDate: DateValue | n
|
|
|
44
45
|
declare function getDayFormatter(locale: string, timeZone: string): DateFormatter;
|
|
45
46
|
declare function getMonthFormatter(locale: string, timeZone: string): DateFormatter;
|
|
46
47
|
|
|
47
|
-
declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
48
|
-
declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
49
|
-
declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
|
|
50
|
-
declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
|
|
51
|
-
declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
|
|
48
|
+
declare function getStartOfWeek(date: DateValue$1, locale: string, firstDayOfWeek?: number): DateValue$1;
|
|
49
|
+
declare function getEndOfWeek(date: DateValue$1, locale: string, firstDayOfWeek?: number): DateValue$1;
|
|
50
|
+
declare function getDaysInWeek(weekIndex: number, from: DateValue$1, locale: string, firstDayOfWeek?: number): DateValue$1[];
|
|
51
|
+
declare function getMonthDays(from: DateValue$1, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue$1[][];
|
|
52
|
+
declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue$1 | Date>(value: T) => {
|
|
52
53
|
value: T;
|
|
53
54
|
short: string;
|
|
54
55
|
long: string;
|
|
55
56
|
narrow: string;
|
|
56
57
|
};
|
|
57
|
-
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
58
|
+
declare function getWeekDays(date: DateValue$1, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
58
59
|
value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
59
60
|
short: string;
|
|
60
61
|
long: string;
|
|
61
62
|
narrow: string;
|
|
62
63
|
}[];
|
|
63
64
|
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"]): string[];
|
|
65
|
+
declare function getWeekOfYear(date: DateValue$1, locale: string): number;
|
|
64
66
|
|
|
65
67
|
interface YearsRange {
|
|
66
68
|
from: number;
|
|
@@ -73,9 +75,9 @@ declare function getDecadeRange(year: number, opts?: {
|
|
|
73
75
|
}): number[];
|
|
74
76
|
|
|
75
77
|
declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
|
|
76
|
-
declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
77
|
-
declare function setDate(date: DateValue, startDate: DateValue, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue, maxValue: DateValue): DateValue | undefined;
|
|
78
|
-
declare function getPreviousAvailableDate(date: DateValue, minValue: DateValue, locale: string, isDateUnavailable?: DateAvailableFn): DateValue | undefined;
|
|
78
|
+
declare function setCalendar(date: DateValue$1, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
79
|
+
declare function setDate(date: DateValue$1, startDate: DateValue$1, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue$1, maxValue: DateValue$1): DateValue$1 | undefined;
|
|
80
|
+
declare function getPreviousAvailableDate(date: DateValue$1, minValue: DateValue$1, locale: string, isDateUnavailable?: DateAvailableFn): DateValue$1 | undefined;
|
|
79
81
|
|
|
80
82
|
interface AdjustDateParams {
|
|
81
83
|
startDate: DateValue;
|
|
@@ -96,6 +98,6 @@ declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue
|
|
|
96
98
|
|
|
97
99
|
declare function parseDateString(date: string, locale: string, timeZone: string): DateValue | undefined;
|
|
98
100
|
|
|
99
|
-
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
|
101
|
+
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue$1, DateValue$1];
|
|
100
102
|
|
|
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, isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
|
103
|
+
export { type AdjustDateParams, type AdjustDateReturn, type DateAdjustFn, type DateGranularity, type DateRangePreset, type DateValue, 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, getWeekOfYear, getWeekdayFormats, getYearsRange, isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _internationalized_date from '@internationalized/date';
|
|
2
|
-
import {
|
|
2
|
+
import { CalendarDate, CalendarDateTime, ZonedDateTime, DateDuration, DateValue as DateValue$1, DateFormatter, Calendar } from '@internationalized/date';
|
|
3
3
|
|
|
4
|
+
type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;
|
|
4
5
|
type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
|
|
5
6
|
type DateAlignment = "start" | "end" | "center";
|
|
6
7
|
type DateAvailableFn = (date: DateValue, locale: string) => boolean;
|
|
@@ -14,8 +15,8 @@ type DateAdjustFn = (options: {
|
|
|
14
15
|
};
|
|
15
16
|
type DateRangePreset = "thisWeek" | "lastWeek" | "thisMonth" | "lastMonth" | "thisQuarter" | "lastQuarter" | "thisYear" | "lastYear" | "last3Days" | "last7Days" | "last14Days" | "last30Days" | "last90Days";
|
|
16
17
|
|
|
17
|
-
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
|
|
18
|
-
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined):
|
|
18
|
+
declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
|
|
19
|
+
declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
19
20
|
|
|
20
21
|
declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
|
|
21
22
|
declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
@@ -23,11 +24,11 @@ declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | nul
|
|
|
23
24
|
declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
24
25
|
declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
|
|
25
26
|
|
|
26
|
-
declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
27
|
-
declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
28
|
-
declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
29
|
-
declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
|
|
30
|
-
declare function constrainValue(date:
|
|
27
|
+
declare function alignCenter(date: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
28
|
+
declare function alignStart(date: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
29
|
+
declare function alignEnd(date: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
30
|
+
declare function constrainStart(date: DateValue$1, aligned: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1, max?: DateValue$1): DateValue$1;
|
|
31
|
+
declare function constrainValue<T extends DateValue$1>(date: T, minValue?: DateValue$1, maxValue?: DateValue$1): T;
|
|
31
32
|
|
|
32
33
|
declare function getUnitDuration(duration: DateDuration): {
|
|
33
34
|
years?: number;
|
|
@@ -44,23 +45,24 @@ declare function formatVisibleRange(startDate: DateValue, endDate: DateValue | n
|
|
|
44
45
|
declare function getDayFormatter(locale: string, timeZone: string): DateFormatter;
|
|
45
46
|
declare function getMonthFormatter(locale: string, timeZone: string): DateFormatter;
|
|
46
47
|
|
|
47
|
-
declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
48
|
-
declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
|
|
49
|
-
declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
|
|
50
|
-
declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
|
|
51
|
-
declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
|
|
48
|
+
declare function getStartOfWeek(date: DateValue$1, locale: string, firstDayOfWeek?: number): DateValue$1;
|
|
49
|
+
declare function getEndOfWeek(date: DateValue$1, locale: string, firstDayOfWeek?: number): DateValue$1;
|
|
50
|
+
declare function getDaysInWeek(weekIndex: number, from: DateValue$1, locale: string, firstDayOfWeek?: number): DateValue$1[];
|
|
51
|
+
declare function getMonthDays(from: DateValue$1, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue$1[][];
|
|
52
|
+
declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue$1 | Date>(value: T) => {
|
|
52
53
|
value: T;
|
|
53
54
|
short: string;
|
|
54
55
|
long: string;
|
|
55
56
|
narrow: string;
|
|
56
57
|
};
|
|
57
|
-
declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
58
|
+
declare function getWeekDays(date: DateValue$1, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
|
|
58
59
|
value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
|
|
59
60
|
short: string;
|
|
60
61
|
long: string;
|
|
61
62
|
narrow: string;
|
|
62
63
|
}[];
|
|
63
64
|
declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"]): string[];
|
|
65
|
+
declare function getWeekOfYear(date: DateValue$1, locale: string): number;
|
|
64
66
|
|
|
65
67
|
interface YearsRange {
|
|
66
68
|
from: number;
|
|
@@ -73,9 +75,9 @@ declare function getDecadeRange(year: number, opts?: {
|
|
|
73
75
|
}): number[];
|
|
74
76
|
|
|
75
77
|
declare function getTodayDate(timeZone?: string): _internationalized_date.CalendarDate;
|
|
76
|
-
declare function setCalendar(date: DateValue, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
77
|
-
declare function setDate(date: DateValue, startDate: DateValue, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue, maxValue: DateValue): DateValue | undefined;
|
|
78
|
-
declare function getPreviousAvailableDate(date: DateValue, minValue: DateValue, locale: string, isDateUnavailable?: DateAvailableFn): DateValue | undefined;
|
|
78
|
+
declare function setCalendar(date: DateValue$1, calendar: Calendar): _internationalized_date.CalendarDateTime;
|
|
79
|
+
declare function setDate(date: DateValue$1, startDate: DateValue$1, isDateUnavailable: DateAvailableFn, locale: string, minValue: DateValue$1, maxValue: DateValue$1): DateValue$1 | undefined;
|
|
80
|
+
declare function getPreviousAvailableDate(date: DateValue$1, minValue: DateValue$1, locale: string, isDateUnavailable?: DateAvailableFn): DateValue$1 | undefined;
|
|
79
81
|
|
|
80
82
|
interface AdjustDateParams {
|
|
81
83
|
startDate: DateValue;
|
|
@@ -96,6 +98,6 @@ declare function getPreviousSection(focusedDate: DateValue, startDate: DateValue
|
|
|
96
98
|
|
|
97
99
|
declare function parseDateString(date: string, locale: string, timeZone: string): DateValue | undefined;
|
|
98
100
|
|
|
99
|
-
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
|
|
101
|
+
declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue$1, DateValue$1];
|
|
100
102
|
|
|
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, isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
|
103
|
+
export { type AdjustDateParams, type AdjustDateReturn, type DateAdjustFn, type DateGranularity, type DateRangePreset, type DateValue, 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, getWeekOfYear, getWeekdayFormats, getYearsRange, isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
package/dist/index.js
CHANGED
|
@@ -52,14 +52,27 @@ function constrainStart(date$1, aligned, duration, locale, min, max) {
|
|
|
52
52
|
return aligned;
|
|
53
53
|
}
|
|
54
54
|
function constrainValue(date$1, minValue, maxValue) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
55
|
+
const dateOnly = date.toCalendarDate(date$1);
|
|
56
|
+
const minOnly = minValue ? date.toCalendarDate(minValue) : void 0;
|
|
57
|
+
const maxOnly = maxValue ? date.toCalendarDate(maxValue) : void 0;
|
|
58
|
+
let constrainedDateOnly = dateOnly;
|
|
59
|
+
if (minOnly) {
|
|
60
|
+
constrainedDateOnly = date.maxDate(constrainedDateOnly, minOnly);
|
|
61
|
+
}
|
|
62
|
+
if (maxOnly) {
|
|
63
|
+
constrainedDateOnly = date.minDate(constrainedDateOnly, maxOnly);
|
|
64
|
+
}
|
|
65
|
+
if (constrainedDateOnly.compare(dateOnly) === 0) {
|
|
66
|
+
return date$1;
|
|
67
|
+
}
|
|
68
|
+
if ("hour" in date$1) {
|
|
69
|
+
return date$1.set({
|
|
70
|
+
year: constrainedDateOnly.year,
|
|
71
|
+
month: constrainedDateOnly.month,
|
|
72
|
+
day: constrainedDateOnly.day
|
|
73
|
+
});
|
|
61
74
|
}
|
|
62
|
-
return
|
|
75
|
+
return constrainedDateOnly;
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
// src/align.ts
|
|
@@ -253,6 +266,21 @@ function getMonthNames(locale, format = "long") {
|
|
|
253
266
|
}
|
|
254
267
|
return monthNames;
|
|
255
268
|
}
|
|
269
|
+
function getWeekOfYear(date$1, locale) {
|
|
270
|
+
const mondayOfWeek = date.startOfWeek(date$1, locale, "mon");
|
|
271
|
+
const year = mondayOfWeek.year;
|
|
272
|
+
const jan4 = mondayOfWeek.set({ month: 1, day: 4 });
|
|
273
|
+
const week1Monday = date.startOfWeek(jan4, locale, "mon");
|
|
274
|
+
const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
|
|
275
|
+
const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
|
|
276
|
+
if (julianMonday >= julianWeek1) {
|
|
277
|
+
return 1 + Math.floor((julianMonday - julianWeek1) / 7);
|
|
278
|
+
}
|
|
279
|
+
const prevJan4 = mondayOfWeek.set({ year: year - 1, month: 1, day: 4 });
|
|
280
|
+
const prevWeek1Monday = date.startOfWeek(prevJan4, locale, "mon");
|
|
281
|
+
const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
|
|
282
|
+
return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
|
|
283
|
+
}
|
|
256
284
|
|
|
257
285
|
// src/date-year.ts
|
|
258
286
|
function getYearsRange(range) {
|
|
@@ -595,6 +623,7 @@ exports.getStartOfWeek = getStartOfWeek;
|
|
|
595
623
|
exports.getTodayDate = getTodayDate;
|
|
596
624
|
exports.getUnitDuration = getUnitDuration;
|
|
597
625
|
exports.getWeekDays = getWeekDays;
|
|
626
|
+
exports.getWeekOfYear = getWeekOfYear;
|
|
598
627
|
exports.getWeekdayFormats = getWeekdayFormats;
|
|
599
628
|
exports.getYearsRange = getYearsRange;
|
|
600
629
|
exports.isDateEqual = isDateEqual;
|
package/dist/index.mjs
CHANGED
|
@@ -50,14 +50,27 @@ function constrainStart(date, aligned, duration, locale, min, max) {
|
|
|
50
50
|
return aligned;
|
|
51
51
|
}
|
|
52
52
|
function constrainValue(date, minValue, maxValue) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const dateOnly = toCalendarDate(date);
|
|
54
|
+
const minOnly = minValue ? toCalendarDate(minValue) : void 0;
|
|
55
|
+
const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
|
|
56
|
+
let constrainedDateOnly = dateOnly;
|
|
57
|
+
if (minOnly) {
|
|
58
|
+
constrainedDateOnly = maxDate(constrainedDateOnly, minOnly);
|
|
56
59
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
60
|
+
if (maxOnly) {
|
|
61
|
+
constrainedDateOnly = minDate(constrainedDateOnly, maxOnly);
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
if (constrainedDateOnly.compare(dateOnly) === 0) {
|
|
64
|
+
return date;
|
|
65
|
+
}
|
|
66
|
+
if ("hour" in date) {
|
|
67
|
+
return date.set({
|
|
68
|
+
year: constrainedDateOnly.year,
|
|
69
|
+
month: constrainedDateOnly.month,
|
|
70
|
+
day: constrainedDateOnly.day
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return constrainedDateOnly;
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
// src/align.ts
|
|
@@ -251,6 +264,21 @@ function getMonthNames(locale, format = "long") {
|
|
|
251
264
|
}
|
|
252
265
|
return monthNames;
|
|
253
266
|
}
|
|
267
|
+
function getWeekOfYear(date, locale) {
|
|
268
|
+
const mondayOfWeek = startOfWeek(date, locale, "mon");
|
|
269
|
+
const year = mondayOfWeek.year;
|
|
270
|
+
const jan4 = mondayOfWeek.set({ month: 1, day: 4 });
|
|
271
|
+
const week1Monday = startOfWeek(jan4, locale, "mon");
|
|
272
|
+
const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
|
|
273
|
+
const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
|
|
274
|
+
if (julianMonday >= julianWeek1) {
|
|
275
|
+
return 1 + Math.floor((julianMonday - julianWeek1) / 7);
|
|
276
|
+
}
|
|
277
|
+
const prevJan4 = mondayOfWeek.set({ year: year - 1, month: 1, day: 4 });
|
|
278
|
+
const prevWeek1Monday = startOfWeek(prevJan4, locale, "mon");
|
|
279
|
+
const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
|
|
280
|
+
return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
|
|
281
|
+
}
|
|
254
282
|
|
|
255
283
|
// src/date-year.ts
|
|
256
284
|
function getYearsRange(range) {
|
|
@@ -560,4 +588,4 @@ function getDateRangePreset(preset, locale, timeZone) {
|
|
|
560
588
|
}
|
|
561
589
|
}
|
|
562
590
|
|
|
563
|
-
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, isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
|
591
|
+
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, getWeekOfYear, getWeekdayFormats, getYearsRange, isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid, normalizeYear, parseDateString, setCalendar, setDate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/date-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.0",
|
|
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.11.0",
|
|
31
31
|
"clean-package": "2.2.0"
|
|
32
32
|
},
|
|
33
33
|
"module": "dist/index.mjs",
|