@zag-js/date-utils 1.2.1 → 1.3.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 CHANGED
@@ -18,12 +18,10 @@ declare function alignDate(date: DateValue, alignment: DateAlignment, duration:
18
18
  declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
19
19
 
20
20
  declare function isDateEqual(dateA: DateValue, dateB?: DateValue | null): boolean;
21
- declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
22
- declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
23
21
  declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
24
- declare function isDateOutsideVisibleRange(date: DateValue, startDate: DateValue, endDate: DateValue): boolean;
25
- declare function isPreviousVisibleRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
26
- declare function isNextVisibleRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
22
+ declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
23
+ declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
24
+ declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
27
25
 
28
26
  declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
29
27
  declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
@@ -98,4 +96,4 @@ declare function parseDateString(date: string, locale: string, timeZone: string)
98
96
 
99
97
  declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
100
98
 
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 };
99
+ 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 };
package/dist/index.d.ts CHANGED
@@ -18,12 +18,10 @@ declare function alignDate(date: DateValue, alignment: DateAlignment, duration:
18
18
  declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): DateValue;
19
19
 
20
20
  declare function isDateEqual(dateA: DateValue, dateB?: DateValue | null): boolean;
21
- declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
22
- declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
23
21
  declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
24
- declare function isDateOutsideVisibleRange(date: DateValue, startDate: DateValue, endDate: DateValue): boolean;
25
- declare function isPreviousVisibleRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
26
- declare function isNextVisibleRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
22
+ declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
23
+ declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
24
+ declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
27
25
 
28
26
  declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
29
27
  declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
@@ -98,4 +96,4 @@ declare function parseDateString(date: string, locale: string, timeZone: string)
98
96
 
99
97
  declare function getDateRangePreset(preset: DateRangePreset, locale: string, timeZone: string): [DateValue, DateValue];
100
98
 
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 };
99
+ 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 };
package/dist/index.js CHANGED
@@ -85,31 +85,21 @@ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
85
85
  function isDateEqual(dateA, dateB) {
86
86
  return dateB != null && date.isSameDay(dateA, dateB);
87
87
  }
88
- function isDateInvalid(date, minValue, maxValue) {
89
- return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
90
- }
91
- function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
92
- return isDateOutsideVisibleRange(date, startDate, endDate) || isDateInvalid(date, minValue, maxValue);
93
- }
94
88
  function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
95
- if (!date) {
96
- return false;
97
- }
98
- if (isUnavailable?.(date, locale)) {
99
- return true;
100
- }
101
- return isDateInvalid(date, minValue, maxValue);
89
+ if (!date) return false;
90
+ if (isUnavailable?.(date, locale)) return true;
91
+ return isDateOutsideRange(date, minValue, maxValue);
102
92
  }
103
- function isDateOutsideVisibleRange(date, startDate, endDate) {
104
- return date.compare(startDate) < 0 || date.compare(endDate) > 0;
93
+ function isDateOutsideRange(date, startDate, endDate) {
94
+ return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
105
95
  }
106
- function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
96
+ function isPreviousRangeInvalid(startDate, minValue, maxValue) {
107
97
  const prevDate = startDate.subtract({ days: 1 });
108
- return date.isSameDay(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
98
+ return date.isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
109
99
  }
110
- function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
100
+ function isNextRangeInvalid(endDate, minValue, maxValue) {
111
101
  const nextDate = endDate.add({ days: 1 });
112
- return date.isSameDay(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
102
+ return date.isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
113
103
  }
114
104
 
115
105
  // src/duration.ts
@@ -316,7 +306,7 @@ function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
316
306
  return function getDate(options) {
317
307
  const { startDate, focusedDate } = options;
318
308
  const endDate = getEndDate(startDate, visibleDuration);
319
- if (isDateInvalid(focusedDate, minValue, maxValue)) {
309
+ if (isDateOutsideRange(focusedDate, minValue, maxValue)) {
320
310
  return {
321
311
  startDate,
322
312
  focusedDate: constrainValue(focusedDate, minValue, maxValue),
@@ -603,13 +593,11 @@ exports.getUnitDuration = getUnitDuration;
603
593
  exports.getWeekDays = getWeekDays;
604
594
  exports.getWeekdayFormats = getWeekdayFormats;
605
595
  exports.getYearsRange = getYearsRange;
606
- exports.isDateDisabled = isDateDisabled;
607
596
  exports.isDateEqual = isDateEqual;
608
- exports.isDateInvalid = isDateInvalid;
609
- exports.isDateOutsideVisibleRange = isDateOutsideVisibleRange;
597
+ exports.isDateOutsideRange = isDateOutsideRange;
610
598
  exports.isDateUnavailable = isDateUnavailable;
611
- exports.isNextVisibleRangeInvalid = isNextVisibleRangeInvalid;
612
- exports.isPreviousVisibleRangeInvalid = isPreviousVisibleRangeInvalid;
599
+ exports.isNextRangeInvalid = isNextRangeInvalid;
600
+ exports.isPreviousRangeInvalid = isPreviousRangeInvalid;
613
601
  exports.normalizeYear = normalizeYear;
614
602
  exports.parseDateString = parseDateString;
615
603
  exports.setCalendar = setCalendar;
package/dist/index.mjs CHANGED
@@ -83,31 +83,21 @@ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
83
83
  function isDateEqual(dateA, dateB) {
84
84
  return dateB != null && isSameDay(dateA, dateB);
85
85
  }
86
- function isDateInvalid(date, minValue, maxValue) {
87
- return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
88
- }
89
- function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
90
- return isDateOutsideVisibleRange(date, startDate, endDate) || isDateInvalid(date, minValue, maxValue);
91
- }
92
86
  function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
93
- if (!date) {
94
- return false;
95
- }
96
- if (isUnavailable?.(date, locale)) {
97
- return true;
98
- }
99
- return isDateInvalid(date, minValue, maxValue);
87
+ if (!date) return false;
88
+ if (isUnavailable?.(date, locale)) return true;
89
+ return isDateOutsideRange(date, minValue, maxValue);
100
90
  }
101
- function isDateOutsideVisibleRange(date, startDate, endDate) {
102
- return date.compare(startDate) < 0 || date.compare(endDate) > 0;
91
+ function isDateOutsideRange(date, startDate, endDate) {
92
+ return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
103
93
  }
104
- function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
94
+ function isPreviousRangeInvalid(startDate, minValue, maxValue) {
105
95
  const prevDate = startDate.subtract({ days: 1 });
106
- return isSameDay(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
96
+ return isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
107
97
  }
108
- function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
98
+ function isNextRangeInvalid(endDate, minValue, maxValue) {
109
99
  const nextDate = endDate.add({ days: 1 });
110
- return isSameDay(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
100
+ return isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
111
101
  }
112
102
 
113
103
  // src/duration.ts
@@ -314,7 +304,7 @@ function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
314
304
  return function getDate(options) {
315
305
  const { startDate, focusedDate } = options;
316
306
  const endDate = getEndDate(startDate, visibleDuration);
317
- if (isDateInvalid(focusedDate, minValue, maxValue)) {
307
+ if (isDateOutsideRange(focusedDate, minValue, maxValue)) {
318
308
  return {
319
309
  startDate,
320
310
  focusedDate: constrainValue(focusedDate, minValue, maxValue),
@@ -566,4 +556,4 @@ function getDateRangePreset(preset, locale, timeZone) {
566
556
  }
567
557
  }
568
558
 
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 };
559
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/date-utils",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Date utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",