@zag-js/date-utils 0.10.2 → 0.10.4

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.
Files changed (104) hide show
  1. package/dist/align.d.ts +4 -7
  2. package/dist/align.js +11 -83
  3. package/dist/align.mjs +24 -9
  4. package/dist/assertion.d.ts +10 -13
  5. package/dist/assertion.js +19 -48
  6. package/dist/assertion.mjs +36 -20
  7. package/dist/constrain.d.ts +6 -9
  8. package/dist/constrain.js +26 -52
  9. package/dist/constrain.mjs +58 -14
  10. package/dist/duration.d.ts +3 -7
  11. package/dist/duration.js +6 -30
  12. package/dist/duration.mjs +18 -8
  13. package/dist/format-date.d.ts +2 -5
  14. package/dist/format-date.js +32 -54
  15. package/dist/format-date.mjs +53 -6
  16. package/dist/format-range.d.ts +2 -5
  17. package/dist/format-range.js +5 -28
  18. package/dist/format-range.mjs +24 -6
  19. package/dist/format-selected-date.d.ts +2 -5
  20. package/dist/format-selected-date.js +10 -77
  21. package/dist/format-selected-date.mjs +15 -9
  22. package/dist/format-visible-range.d.ts +2 -5
  23. package/dist/format-visible-range.js +12 -68
  24. package/dist/format-visible-range.mjs +22 -9
  25. package/dist/get-day-formatter.d.ts +2 -5
  26. package/dist/get-day-formatter.js +9 -37
  27. package/dist/get-day-formatter.mjs +16 -7
  28. package/dist/get-decade-range.d.ts +1 -3
  29. package/dist/get-decade-range.js +5 -28
  30. package/dist/get-decade-range.mjs +11 -6
  31. package/dist/get-end-of-week.d.ts +2 -6
  32. package/dist/get-era-format.d.ts +2 -5
  33. package/dist/get-era-format.js +5 -28
  34. package/dist/get-era-format.mjs +5 -6
  35. package/dist/get-month-days.d.ts +3 -6
  36. package/dist/get-month-days.js +13 -45
  37. package/dist/get-month-days.mjs +24 -9
  38. package/dist/get-month-formatter.d.ts +2 -5
  39. package/dist/get-month-formatter.js +10 -38
  40. package/dist/get-month-formatter.mjs +15 -7
  41. package/dist/get-month-names.d.ts +1 -3
  42. package/dist/get-month-names.js +5 -28
  43. package/dist/get-month-names.mjs +11 -6
  44. package/dist/get-start-of-week.d.ts +2 -6
  45. package/dist/get-start-of-week.js +10 -32
  46. package/dist/get-start-of-week.mjs +9 -6
  47. package/dist/get-week-days.d.ts +3 -7
  48. package/dist/get-week-days.js +8 -55
  49. package/dist/get-week-days.mjs +11 -8
  50. package/dist/get-weekday-formats.d.ts +2 -5
  51. package/dist/get-weekday-formats.js +10 -32
  52. package/dist/get-weekday-formats.mjs +18 -6
  53. package/dist/get-year-range.d.ts +2 -4
  54. package/dist/get-year-range.js +5 -28
  55. package/dist/get-year-range.mjs +9 -6
  56. package/dist/index.d.ts +20 -21
  57. package/dist/index.js +74 -740
  58. package/dist/index.mjs +19 -138
  59. package/dist/mutation.d.ts +10 -14
  60. package/dist/mutation.js +17 -59
  61. package/dist/mutation.mjs +40 -21
  62. package/dist/pagination.d.ts +19 -23
  63. package/dist/pagination.js +35 -134
  64. package/dist/pagination.mjs +179 -25
  65. package/dist/parse-date.d.ts +2 -5
  66. package/dist/parse-date.js +13 -35
  67. package/dist/parse-date.mjs +40 -6
  68. package/dist/types.d.ts +8 -11
  69. package/package.json +3 -8
  70. package/src/assertion.ts +1 -1
  71. package/src/constrain.ts +2 -2
  72. package/src/format-date.ts +1 -1
  73. package/src/format-selected-date.ts +1 -1
  74. package/src/format-visible-range.ts +1 -1
  75. package/src/get-month-days.ts +1 -1
  76. package/src/get-start-of-week.ts +1 -1
  77. package/src/get-weekday-formats.ts +1 -1
  78. package/src/mutation.ts +8 -1
  79. package/src/pagination.ts +8 -1
  80. package/dist/chunk-5HGHDJ3L.mjs +0 -14
  81. package/dist/chunk-6FNTXW54.mjs +0 -52
  82. package/dist/chunk-6LXTZHZP.mjs +0 -22
  83. package/dist/chunk-AMZ7CJ5F.mjs +0 -18
  84. package/dist/chunk-BUT5IUNZ.mjs +0 -32
  85. package/dist/chunk-FJKH6IJZ.mjs +0 -21
  86. package/dist/chunk-G4VVKINZ.mjs +0 -14
  87. package/dist/chunk-HKHGJ6WS.mjs +0 -27
  88. package/dist/chunk-HLAN6TUA.mjs +0 -45
  89. package/dist/chunk-KBGJA6NB.mjs +0 -55
  90. package/dist/chunk-KLHRN7WS.mjs +0 -20
  91. package/dist/chunk-KN3YMOSL.mjs +0 -8
  92. package/dist/chunk-KQVWH4YA.mjs +0 -29
  93. package/dist/chunk-LGEGBP3O.mjs +0 -20
  94. package/dist/chunk-MGPXEJO4.mjs +0 -71
  95. package/dist/chunk-NV7UFBMY.mjs +0 -30
  96. package/dist/chunk-POBWDZPE.mjs +0 -200
  97. package/dist/chunk-SI75FOJ2.mjs +0 -11
  98. package/dist/chunk-TTJVXKJY.mjs +0 -12
  99. package/dist/chunk-WQYMLJUJ.mjs +0 -42
  100. package/dist/chunk-ZSLC7OI2.mjs +0 -22
  101. package/dist/get-end-of-week.js +0 -42
  102. package/dist/get-end-of-week.mjs +0 -11
  103. package/dist/types.js +0 -18
  104. package/dist/types.mjs +0 -0
@@ -1,4 +1,4 @@
1
- import { DateValue, endOfMonth, isSameDay, startOfMonth } from "@internationalized/date"
1
+ import { type DateValue, endOfMonth, isSameDay, startOfMonth } from "@internationalized/date"
2
2
  import { getDayFormatter } from "./get-day-formatter"
3
3
  import { getMonthFormatter } from "./get-month-formatter"
4
4
 
@@ -1,4 +1,4 @@
1
- import { DateValue, getWeeksInMonth, isSameDay } from "@internationalized/date"
1
+ import { type DateValue, getWeeksInMonth, isSameDay } from "@internationalized/date"
2
2
  import { getStartOfWeek } from "./get-start-of-week"
3
3
 
4
4
  export function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number) {
@@ -1,4 +1,4 @@
1
- import { DateValue, getDayOfWeek } from "@internationalized/date"
1
+ import { type DateValue, getDayOfWeek } from "@internationalized/date"
2
2
 
3
3
  export function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek: number = 0) {
4
4
  const day = getDayOfWeek(date, locale)
@@ -1,4 +1,4 @@
1
- import { DateValue, DateFormatter } from "@internationalized/date"
1
+ import { type DateValue, DateFormatter } from "@internationalized/date"
2
2
 
3
3
  export function getWeekdayFormats(locale: string, timeZone: string) {
4
4
  const longFormat = new DateFormatter(locale, { weekday: "long", timeZone })
package/src/mutation.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { Calendar, DateValue, getLocalTimeZone, toCalendar, toCalendarDateTime, today } from "@internationalized/date"
1
+ import {
2
+ type Calendar,
3
+ type DateValue,
4
+ getLocalTimeZone,
5
+ toCalendar,
6
+ toCalendarDateTime,
7
+ today,
8
+ } from "@internationalized/date"
2
9
  import { constrainValue } from "./constrain"
3
10
  import type { DateAvailableFn } from "./types"
4
11
 
package/src/pagination.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { DateDuration, DateValue, endOfMonth, endOfWeek, startOfMonth, startOfWeek } from "@internationalized/date"
1
+ import {
2
+ type DateDuration,
3
+ type DateValue,
4
+ endOfMonth,
5
+ endOfWeek,
6
+ startOfMonth,
7
+ startOfWeek,
8
+ } from "@internationalized/date"
2
9
  import { isDateInvalid } from "./assertion"
3
10
  import { alignEnd, alignStart, constrainStart, constrainValue } from "./constrain"
4
11
  import { getEndDate, getUnitDuration } from "./duration"
@@ -1,14 +0,0 @@
1
- // src/get-month-names.ts
2
- function getMonthNames(locale, format = "long") {
3
- const date = new Date(2021, 0, 1);
4
- const monthNames = [];
5
- for (let i = 0; i < 12; i++) {
6
- monthNames.push(date.toLocaleString(locale, { month: format }));
7
- date.setMonth(date.getMonth() + 1);
8
- }
9
- return monthNames;
10
- }
11
-
12
- export {
13
- getMonthNames
14
- };
@@ -1,52 +0,0 @@
1
- import {
2
- constrainValue
3
- } from "./chunk-MGPXEJO4.mjs";
4
-
5
- // src/mutation.ts
6
- import { getLocalTimeZone, toCalendar, toCalendarDateTime, today } from "@internationalized/date";
7
- function getTodayDate(timeZone) {
8
- return today(timeZone ?? getLocalTimeZone());
9
- }
10
- function getNextDay(date) {
11
- return date.add({ days: 1 });
12
- }
13
- function getPreviousDay(date) {
14
- return date.subtract({ days: 1 });
15
- }
16
- function setMonth(date, month) {
17
- return date.set({ month });
18
- }
19
- function setYear(date, year) {
20
- return date.set({ year });
21
- }
22
- function setCalendar(date, calendar) {
23
- return toCalendar(toCalendarDateTime(date), calendar);
24
- }
25
- function setDate(date, startDate, isDateUnavailable, locale, minValue, maxValue) {
26
- let result;
27
- result = constrainValue(date, minValue, maxValue);
28
- result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable);
29
- return result;
30
- }
31
- function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable) {
32
- if (!isDateUnavailable) {
33
- return date;
34
- }
35
- while (date.compare(minValue) >= 0 && isDateUnavailable(date, locale)) {
36
- date = date.subtract({ days: 1 });
37
- }
38
- if (date.compare(minValue) >= 0) {
39
- return date;
40
- }
41
- }
42
-
43
- export {
44
- getTodayDate,
45
- getNextDay,
46
- getPreviousDay,
47
- setMonth,
48
- setYear,
49
- setCalendar,
50
- setDate,
51
- getPreviousAvailableDate
52
- };
@@ -1,22 +0,0 @@
1
- import {
2
- formatRange
3
- } from "./chunk-HKHGJ6WS.mjs";
4
- import {
5
- getDayFormatter
6
- } from "./chunk-FJKH6IJZ.mjs";
7
-
8
- // src/format-selected-date.ts
9
- import { isSameDay } from "@internationalized/date";
10
- function formatSelectedDate(startDate, endDate, locale, timeZone) {
11
- let start = startDate;
12
- let end = endDate ?? startDate;
13
- let formatter = getDayFormatter(locale, timeZone);
14
- if (isSameDay(start, end)) {
15
- return formatter.format(start.toDate(timeZone));
16
- }
17
- return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
18
- }
19
-
20
- export {
21
- formatSelectedDate
22
- };
@@ -1,18 +0,0 @@
1
- import {
2
- getWeekdayFormats
3
- } from "./chunk-KLHRN7WS.mjs";
4
- import {
5
- getStartOfWeek
6
- } from "./chunk-SI75FOJ2.mjs";
7
-
8
- // src/get-week-days.ts
9
- function getWeekDays(date, startOfWeekProp, timeZone, locale) {
10
- const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
11
- const weeks = [...new Array(7).keys()];
12
- const format = getWeekdayFormats(locale, timeZone);
13
- return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
14
- }
15
-
16
- export {
17
- getWeekDays
18
- };
@@ -1,32 +0,0 @@
1
- import {
2
- alignCenter,
3
- alignEnd,
4
- alignStart
5
- } from "./chunk-MGPXEJO4.mjs";
6
-
7
- // src/align.ts
8
- function alignDate(date, alignment, duration, locale, min, max) {
9
- switch (alignment) {
10
- case "start":
11
- return alignStart(date, duration, locale, min, max);
12
- case "end":
13
- return alignEnd(date, duration, locale, min, max);
14
- case "center":
15
- default:
16
- return alignCenter(date, duration, locale, min, max);
17
- }
18
- }
19
- function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
20
- if (date.compare(startDate) < 0) {
21
- return alignEnd(date, duration, locale, min, max);
22
- }
23
- if (date.compare(endDate) > 0) {
24
- return alignStart(date, duration, locale, min, max);
25
- }
26
- return startDate;
27
- }
28
-
29
- export {
30
- alignDate,
31
- alignStartDate
32
- };
@@ -1,21 +0,0 @@
1
- import {
2
- getEraFormat
3
- } from "./chunk-KN3YMOSL.mjs";
4
-
5
- // src/get-day-formatter.ts
6
- import { DateFormatter, toCalendarDateTime, today } from "@internationalized/date";
7
- function getDayFormatter(locale, timeZone) {
8
- const date = toCalendarDateTime(today(timeZone));
9
- return new DateFormatter(locale, {
10
- weekday: "long",
11
- month: "long",
12
- year: "numeric",
13
- day: "numeric",
14
- era: getEraFormat(date),
15
- timeZone
16
- });
17
- }
18
-
19
- export {
20
- getDayFormatter
21
- };
@@ -1,14 +0,0 @@
1
- // src/get-decade-range.ts
2
- function getDecadeRange(year) {
3
- const computedYear = year - year % 10 - 1;
4
- const years = [];
5
- for (let i = 0; i < 12; i += 1) {
6
- const value = computedYear + i;
7
- years.push(value);
8
- }
9
- return years;
10
- }
11
-
12
- export {
13
- getDecadeRange
14
- };
@@ -1,27 +0,0 @@
1
- // src/format-range.ts
2
- function formatRange(startDate, endDate, formatter, toString, timeZone) {
3
- let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
4
- let separatorIndex = -1;
5
- for (let i = 0; i < parts.length; i++) {
6
- let part = parts[i];
7
- if (part.source === "shared" && part.type === "literal") {
8
- separatorIndex = i;
9
- } else if (part.source === "endRange") {
10
- break;
11
- }
12
- }
13
- let start = "";
14
- let end = "";
15
- for (let i = 0; i < parts.length; i++) {
16
- if (i < separatorIndex) {
17
- start += parts[i].value;
18
- } else if (i > separatorIndex) {
19
- end += parts[i].value;
20
- }
21
- }
22
- return toString(start, end);
23
- }
24
-
25
- export {
26
- formatRange
27
- };
@@ -1,45 +0,0 @@
1
- // src/assertion.ts
2
- import { isSameDay, isToday } from "@internationalized/date";
3
- function isTodayDate(date, timeZone) {
4
- return isToday(date, timeZone);
5
- }
6
- function isDateEqual(dateA, dateB) {
7
- return dateB != null && isSameDay(dateA, dateB);
8
- }
9
- function isDateInvalid(date, minValue, maxValue) {
10
- return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
11
- }
12
- function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
13
- return date.compare(startDate) < 0 || date.compare(endDate) > 0 || isDateInvalid(date, minValue, maxValue);
14
- }
15
- function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
16
- if (!date) {
17
- return false;
18
- }
19
- if (isUnavailable?.(date, locale)) {
20
- return true;
21
- }
22
- return isDateInvalid(date, minValue, maxValue);
23
- }
24
- function isDateOutsideVisibleRange(date, startDate, endDate) {
25
- return date.compare(startDate) < 0 || date.compare(endDate) > 0;
26
- }
27
- function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
28
- const prevDate = startDate.subtract({ days: 1 });
29
- return isSameDay(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
30
- }
31
- function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
32
- const nextDate = endDate.add({ days: 1 });
33
- return isSameDay(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
34
- }
35
-
36
- export {
37
- isTodayDate,
38
- isDateEqual,
39
- isDateInvalid,
40
- isDateDisabled,
41
- isDateUnavailable,
42
- isDateOutsideVisibleRange,
43
- isPreviousVisibleRangeInvalid,
44
- isNextVisibleRangeInvalid
45
- };
@@ -1,55 +0,0 @@
1
- // src/format-date.ts
2
- import { toCalendarDateTime } from "@internationalized/date";
3
- function createRegEx(sign) {
4
- let symbols = "\\s|\\.|-|/|\\\\|,|\\$|\\!|\\?|:|;";
5
- return new RegExp("(^|>|" + symbols + ")(" + sign + ")($|<|" + symbols + ")", "g");
6
- }
7
- function formatDate(value, formatString, locale, timeZone = "UTC") {
8
- const datetime = toCalendarDateTime(value);
9
- const date = datetime.toDate(timeZone);
10
- const formats = {
11
- // Time in ms
12
- T: date.getTime(),
13
- // Minutes
14
- m: date.toLocaleString(locale, { minute: "numeric" }),
15
- mm: date.toLocaleString(locale, { minute: "2-digit" }),
16
- // Seconds
17
- s: date.toLocaleString(locale, { second: "numeric" }),
18
- ss: date.toLocaleString(locale, { second: "2-digit" }),
19
- // Hours
20
- h: date.toLocaleString(locale, { hour: "numeric", hour12: true }),
21
- hh: date.toLocaleString(locale, { hour: "2-digit", hour12: true }),
22
- H: date.toLocaleString(locale, { hour: "numeric", hour12: false }),
23
- HH: date.toLocaleString(locale, { hour: "2-digit", hour12: false }),
24
- // Day period
25
- aa: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLowerCase(),
26
- AA: date.toLocaleString(locale, { hour: "numeric", hour12: true }).toUpperCase(),
27
- // Day of week
28
- E: date.toLocaleString(locale, { weekday: "short" }),
29
- EE: date.toLocaleString(locale, { weekday: "short" }),
30
- EEE: date.toLocaleString(locale, { weekday: "short" }),
31
- EEEE: date.toLocaleString(locale, { weekday: "long" }),
32
- // Date of month
33
- d: datetime.day,
34
- dd: date.toLocaleString(locale, { day: "2-digit" }),
35
- // Months
36
- M: datetime.month + 1,
37
- MM: date.toLocaleString(locale, { month: "2-digit" }),
38
- MMM: date.toLocaleString(locale, { month: "short" }),
39
- MMMM: date.toLocaleString(locale, { month: "long" }),
40
- // Years
41
- yy: date.toLocaleString(locale, { year: "2-digit" }),
42
- yyyy: date.toLocaleString(locale, { year: "numeric" }),
43
- YY: date.toLocaleString(locale, { year: "2-digit" }),
44
- YYYY: date.toLocaleString(locale, { year: "numeric" })
45
- };
46
- let result = formatString;
47
- for (const key in formats) {
48
- result = result.replace(createRegEx(key), "$1" + formats[key] + "$3");
49
- }
50
- return result;
51
- }
52
-
53
- export {
54
- formatDate
55
- };
@@ -1,20 +0,0 @@
1
- // src/get-weekday-formats.ts
2
- import { DateFormatter } from "@internationalized/date";
3
- function getWeekdayFormats(locale, timeZone) {
4
- const longFormat = new DateFormatter(locale, { weekday: "long", timeZone });
5
- const shortFormat = new DateFormatter(locale, { weekday: "short", timeZone });
6
- const narrowFormat = new DateFormatter(locale, { weekday: "narrow", timeZone });
7
- return (value) => {
8
- const date = value instanceof Date ? value : value.toDate(timeZone);
9
- return {
10
- value,
11
- short: shortFormat.format(date),
12
- long: longFormat.format(date),
13
- narrow: narrowFormat.format(date)
14
- };
15
- };
16
- }
17
-
18
- export {
19
- getWeekdayFormats
20
- };
@@ -1,8 +0,0 @@
1
- // src/get-era-format.ts
2
- function getEraFormat(date) {
3
- return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
4
- }
5
-
6
- export {
7
- getEraFormat
8
- };
@@ -1,29 +0,0 @@
1
- import {
2
- getMonthFormatter
3
- } from "./chunk-LGEGBP3O.mjs";
4
- import {
5
- getDayFormatter
6
- } from "./chunk-FJKH6IJZ.mjs";
7
-
8
- // src/format-visible-range.ts
9
- import { endOfMonth, isSameDay, startOfMonth } from "@internationalized/date";
10
- function formatVisibleRange(startDate, endDate, locale, timeZone) {
11
- const start = startDate;
12
- const end = endDate ?? startDate;
13
- const dayFormatter = getDayFormatter(locale, timeZone);
14
- if (!isSameDay(start, startOfMonth(start))) {
15
- return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
16
- }
17
- const monthFormatter = getMonthFormatter(locale, timeZone);
18
- if (isSameDay(end, endOfMonth(start))) {
19
- return monthFormatter.format(start.toDate(timeZone));
20
- }
21
- if (isSameDay(end, endOfMonth(end))) {
22
- return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
23
- }
24
- return "";
25
- }
26
-
27
- export {
28
- formatVisibleRange
29
- };
@@ -1,20 +0,0 @@
1
- import {
2
- getEraFormat
3
- } from "./chunk-KN3YMOSL.mjs";
4
-
5
- // src/get-month-formatter.ts
6
- import { today, toCalendarDate, DateFormatter } from "@internationalized/date";
7
- function getMonthFormatter(locale, timeZone) {
8
- const date = toCalendarDate(today(timeZone));
9
- return new DateFormatter(locale, {
10
- month: "long",
11
- year: "numeric",
12
- era: getEraFormat(date),
13
- calendar: date?.calendar.identifier,
14
- timeZone
15
- });
16
- }
17
-
18
- export {
19
- getMonthFormatter
20
- };
@@ -1,71 +0,0 @@
1
- // src/constrain.ts
2
- import {
3
- maxDate,
4
- minDate,
5
- startOfMonth,
6
- startOfWeek,
7
- startOfYear,
8
- toCalendarDate
9
- } from "@internationalized/date";
10
- function alignCenter(date, duration, locale, min, max) {
11
- let halfDuration = {};
12
- for (let key in duration) {
13
- halfDuration[key] = Math.floor(duration[key] / 2);
14
- if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
15
- halfDuration[key]--;
16
- }
17
- }
18
- let aligned = alignStart(date, duration, locale).subtract(halfDuration);
19
- return constrainStart(date, aligned, duration, locale, min, max);
20
- }
21
- function alignStart(date, duration, locale, min, max) {
22
- let aligned = date;
23
- if (duration.years) {
24
- aligned = startOfYear(date);
25
- } else if (duration.months) {
26
- aligned = startOfMonth(date);
27
- } else if (duration.weeks) {
28
- aligned = startOfWeek(date, locale);
29
- }
30
- return constrainStart(date, aligned, duration, locale, min, max);
31
- }
32
- function alignEnd(date, duration, locale, min, max) {
33
- let d = { ...duration };
34
- if (d.days) {
35
- d.days--;
36
- } else if (d.weeks) {
37
- d.weeks--;
38
- } else if (d.months) {
39
- d.months--;
40
- } else if (d.years) {
41
- d.years--;
42
- }
43
- let aligned = alignStart(date, duration, locale).subtract(d);
44
- return constrainStart(date, aligned, duration, locale, min, max);
45
- }
46
- function constrainStart(date, aligned, duration, locale, min, max) {
47
- if (min && date.compare(min) >= 0) {
48
- aligned = maxDate(aligned, alignStart(toCalendarDate(min), duration, locale));
49
- }
50
- if (max && date.compare(max) <= 0) {
51
- aligned = minDate(aligned, alignEnd(toCalendarDate(max), duration, locale));
52
- }
53
- return aligned;
54
- }
55
- function constrainValue(date, minValue, maxValue) {
56
- if (minValue) {
57
- date = maxDate(date, toCalendarDate(minValue));
58
- }
59
- if (maxValue) {
60
- date = minDate(date, toCalendarDate(maxValue));
61
- }
62
- return date;
63
- }
64
-
65
- export {
66
- alignCenter,
67
- alignStart,
68
- alignEnd,
69
- constrainStart,
70
- constrainValue
71
- };
@@ -1,30 +0,0 @@
1
- import {
2
- getStartOfWeek
3
- } from "./chunk-SI75FOJ2.mjs";
4
-
5
- // src/get-month-days.ts
6
- import { getWeeksInMonth, isSameDay } from "@internationalized/date";
7
- function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
8
- const weekDate = from.add({ weeks: weekIndex });
9
- const dates = [];
10
- let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
11
- while (dates.length < 7) {
12
- dates.push(date);
13
- let nextDate = date.add({ days: 1 });
14
- if (isSameDay(date, nextDate)) {
15
- break;
16
- }
17
- date = nextDate;
18
- }
19
- return dates;
20
- }
21
- function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
22
- const monthWeeks = getWeeksInMonth(from, locale);
23
- const weeks = [...new Array(numOfWeeks ?? monthWeeks).keys()];
24
- return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
25
- }
26
-
27
- export {
28
- getDaysInWeek,
29
- getMonthDays
30
- };