@octanejs/day-picker 0.0.1
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/LICENSE +21 -0
- package/README.md +14 -0
- package/UPSTREAM.md +24 -0
- package/package.json +77 -0
- package/src/DayPicker.tsrx +717 -0
- package/src/UI.ts +121 -0
- package/src/classes/CalendarDay.ts +82 -0
- package/src/classes/CalendarMonth.ts +20 -0
- package/src/classes/CalendarWeek.ts +19 -0
- package/src/classes/DateLib.ts +695 -0
- package/src/classes/index.ts +4 -0
- package/src/components/custom-components.tsrx +237 -0
- package/src/formatters/formatCaption.ts +18 -0
- package/src/formatters/formatDay.ts +17 -0
- package/src/formatters/formatMonthDropdown.ts +16 -0
- package/src/formatters/formatWeekNumber.ts +19 -0
- package/src/formatters/formatWeekNumberHeader.ts +11 -0
- package/src/formatters/formatWeekdayName.ts +17 -0
- package/src/formatters/formatYearDropdown.ts +15 -0
- package/src/formatters/index.ts +7 -0
- package/src/helpers/calculateFocusTarget.ts +79 -0
- package/src/helpers/createGetModifiers.ts +117 -0
- package/src/helpers/endOfBroadcastWeek.ts +22 -0
- package/src/helpers/getBroadcastWeeksInMonth.ts +32 -0
- package/src/helpers/getClassNamesForModifiers.ts +38 -0
- package/src/helpers/getComponents.ts +19 -0
- package/src/helpers/getDataAttributes.ts +17 -0
- package/src/helpers/getDates.ts +87 -0
- package/src/helpers/getDays.ts +19 -0
- package/src/helpers/getDefaultClassNames.ts +36 -0
- package/src/helpers/getDisplayMonths.ts +30 -0
- package/src/helpers/getFocusableDate.ts +66 -0
- package/src/helpers/getFormatters.ts +16 -0
- package/src/helpers/getInitialMonth.ts +35 -0
- package/src/helpers/getLabels.ts +93 -0
- package/src/helpers/getMonthOptions.ts +45 -0
- package/src/helpers/getMonths.ts +89 -0
- package/src/helpers/getNavMonth.ts +35 -0
- package/src/helpers/getNextFocus.ts +45 -0
- package/src/helpers/getNextMonth.ts +46 -0
- package/src/helpers/getPreviousMonth.ts +45 -0
- package/src/helpers/getStyleForModifiers.ts +31 -0
- package/src/helpers/getWeekdays.ts +33 -0
- package/src/helpers/getWeeks.ts +14 -0
- package/src/helpers/getYearOptions.ts +43 -0
- package/src/helpers/index.ts +2 -0
- package/src/helpers/startOfBroadcastWeek.ts +26 -0
- package/src/helpers/useControlledValue.ts +38 -0
- package/src/index.ts +13 -0
- package/src/labels/index.ts +12 -0
- package/src/labels/labelDayButton.ts +29 -0
- package/src/labels/labelGrid.ts +18 -0
- package/src/labels/labelGridcell.ts +26 -0
- package/src/labels/labelMonthDropdown.ts +14 -0
- package/src/labels/labelNav.ts +11 -0
- package/src/labels/labelNext.ts +17 -0
- package/src/labels/labelPrevious.ts +13 -0
- package/src/labels/labelWeekNumber.ts +15 -0
- package/src/labels/labelWeekNumberHeader.ts +14 -0
- package/src/labels/labelWeekday.ts +16 -0
- package/src/labels/labelYearDropdown.ts +14 -0
- package/src/locale/af.ts +48 -0
- package/src/locale/ar-DZ.ts +48 -0
- package/src/locale/ar-EG.ts +48 -0
- package/src/locale/ar-MA.ts +48 -0
- package/src/locale/ar-SA.ts +48 -0
- package/src/locale/ar-TN.ts +48 -0
- package/src/locale/ar.ts +48 -0
- package/src/locale/az.ts +48 -0
- package/src/locale/be-tarask.ts +51 -0
- package/src/locale/be.ts +48 -0
- package/src/locale/bg.ts +48 -0
- package/src/locale/bn.ts +48 -0
- package/src/locale/bs.ts +48 -0
- package/src/locale/ca.ts +48 -0
- package/src/locale/ckb.ts +51 -0
- package/src/locale/cs.ts +48 -0
- package/src/locale/cy.ts +48 -0
- package/src/locale/da.ts +48 -0
- package/src/locale/de-AT.ts +48 -0
- package/src/locale/de.ts +48 -0
- package/src/locale/el.ts +48 -0
- package/src/locale/en-AU.ts +48 -0
- package/src/locale/en-CA.ts +48 -0
- package/src/locale/en-GB.ts +51 -0
- package/src/locale/en-IE.ts +48 -0
- package/src/locale/en-IN.ts +48 -0
- package/src/locale/en-NZ.ts +48 -0
- package/src/locale/en-US.ts +72 -0
- package/src/locale/en-ZA.ts +48 -0
- package/src/locale/eo.ts +48 -0
- package/src/locale/es.ts +48 -0
- package/src/locale/et.ts +48 -0
- package/src/locale/eu.ts +48 -0
- package/src/locale/fa-IR.ts +48 -0
- package/src/locale/fi.ts +48 -0
- package/src/locale/fr-CA.ts +48 -0
- package/src/locale/fr-CH.ts +48 -0
- package/src/locale/fr.ts +48 -0
- package/src/locale/fy.ts +48 -0
- package/src/locale/gd.ts +48 -0
- package/src/locale/gl.ts +48 -0
- package/src/locale/gu.ts +48 -0
- package/src/locale/he.ts +48 -0
- package/src/locale/hi.ts +48 -0
- package/src/locale/hr.ts +48 -0
- package/src/locale/ht.ts +48 -0
- package/src/locale/hu.ts +48 -0
- package/src/locale/hy.ts +48 -0
- package/src/locale/id.ts +48 -0
- package/src/locale/is.ts +48 -0
- package/src/locale/it-CH.ts +48 -0
- package/src/locale/it.ts +48 -0
- package/src/locale/ja-Hira.ts +48 -0
- package/src/locale/ja.ts +48 -0
- package/src/locale/ka.ts +48 -0
- package/src/locale/kk.ts +48 -0
- package/src/locale/km.ts +48 -0
- package/src/locale/kn.ts +48 -0
- package/src/locale/ko.ts +48 -0
- package/src/locale/lb.ts +48 -0
- package/src/locale/lt.ts +48 -0
- package/src/locale/lv.ts +48 -0
- package/src/locale/mk.ts +48 -0
- package/src/locale/mn.ts +48 -0
- package/src/locale/ms.ts +48 -0
- package/src/locale/mt.ts +48 -0
- package/src/locale/nb.ts +48 -0
- package/src/locale/nl-BE.ts +48 -0
- package/src/locale/nl.ts +48 -0
- package/src/locale/nn.ts +48 -0
- package/src/locale/oc.ts +48 -0
- package/src/locale/pl.ts +48 -0
- package/src/locale/pt-BR.ts +48 -0
- package/src/locale/pt.ts +48 -0
- package/src/locale/ro.ts +48 -0
- package/src/locale/ru.ts +48 -0
- package/src/locale/se.ts +48 -0
- package/src/locale/sk.ts +48 -0
- package/src/locale/sl.ts +48 -0
- package/src/locale/sq.ts +48 -0
- package/src/locale/sr-Latn.ts +48 -0
- package/src/locale/sr.ts +48 -0
- package/src/locale/sv.ts +48 -0
- package/src/locale/ta.ts +48 -0
- package/src/locale/te.ts +48 -0
- package/src/locale/th.ts +48 -0
- package/src/locale/tr.ts +48 -0
- package/src/locale/ug.ts +48 -0
- package/src/locale/uk.ts +48 -0
- package/src/locale/uz-Cyrl.ts +48 -0
- package/src/locale/uz.ts +48 -0
- package/src/locale/vi.ts +48 -0
- package/src/locale/zh-CN.ts +48 -0
- package/src/locale/zh-HK.ts +51 -0
- package/src/locale/zh-TW.ts +51 -0
- package/src/locale.ts +108 -0
- package/src/noonDateLib.ts +202 -0
- package/src/selection/useMulti.ts +74 -0
- package/src/selection/useRange.ts +89 -0
- package/src/selection/useSingle.ts +77 -0
- package/src/style.css +451 -0
- package/src/style.css.d.ts +3 -0
- package/src/style.module.css +451 -0
- package/src/style.module.css.d.ts +29 -0
- package/src/types/index.ts +3 -0
- package/src/types/props.ts +671 -0
- package/src/types/selection.ts +97 -0
- package/src/types/shared.ts +346 -0
- package/src/useAnimation.ts +242 -0
- package/src/useCalendar.ts +233 -0
- package/src/useDayPicker.ts +91 -0
- package/src/useFocus.ts +109 -0
- package/src/useSelection.ts +36 -0
- package/src/utils/addToRange.ts +91 -0
- package/src/utils/convertMatchersToTimeZone.ts +88 -0
- package/src/utils/dateMatchModifiers.ts +72 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/rangeContainsDayOfWeek.ts +33 -0
- package/src/utils/rangeContainsModifiers.ts +106 -0
- package/src/utils/rangeIncludesDate.ts +40 -0
- package/src/utils/rangeOverlaps.ts +26 -0
- package/src/utils/toTimeZone.ts +13 -0
- package/src/utils/typeguards.ts +71 -0
- package/status.json +13 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type DateLib, defaultDateLib } from '../classes/DateLib.js';
|
|
2
|
+
import type { Matcher } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
import { rangeIncludesDate } from './rangeIncludesDate.js';
|
|
5
|
+
import {
|
|
6
|
+
isDateAfterType,
|
|
7
|
+
isDateBeforeType,
|
|
8
|
+
isDateInterval,
|
|
9
|
+
isDateRange,
|
|
10
|
+
isDatesArray,
|
|
11
|
+
isDayOfWeekType,
|
|
12
|
+
} from './typeguards.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a given date matches at least one of the specified {@link Matcher}.
|
|
16
|
+
*
|
|
17
|
+
* @param date - The date to check.
|
|
18
|
+
* @param matchers - The matchers to check against.
|
|
19
|
+
* @param dateLib - The date utility library instance.
|
|
20
|
+
* @returns `true` if the date matches any of the matchers, otherwise `false`.
|
|
21
|
+
* @group Utilities
|
|
22
|
+
*/
|
|
23
|
+
export function dateMatchModifiers(
|
|
24
|
+
date: Date,
|
|
25
|
+
matchers: Matcher | Matcher[],
|
|
26
|
+
dateLib: DateLib = defaultDateLib,
|
|
27
|
+
): boolean {
|
|
28
|
+
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
|
|
29
|
+
const { isSameDay, differenceInCalendarDays, isAfter } = dateLib;
|
|
30
|
+
return matchersArr.some((matcher: Matcher) => {
|
|
31
|
+
if (typeof matcher === 'boolean') {
|
|
32
|
+
return matcher;
|
|
33
|
+
}
|
|
34
|
+
if (dateLib.isDate(matcher)) {
|
|
35
|
+
return isSameDay(date, matcher);
|
|
36
|
+
}
|
|
37
|
+
if (isDatesArray(matcher, dateLib)) {
|
|
38
|
+
return matcher.some((matcherDate) => isSameDay(date, matcherDate));
|
|
39
|
+
}
|
|
40
|
+
if (isDateRange(matcher)) {
|
|
41
|
+
return rangeIncludesDate(matcher, date, false, dateLib);
|
|
42
|
+
}
|
|
43
|
+
if (isDayOfWeekType(matcher)) {
|
|
44
|
+
if (!Array.isArray(matcher.dayOfWeek)) {
|
|
45
|
+
return matcher.dayOfWeek === date.getDay();
|
|
46
|
+
}
|
|
47
|
+
return matcher.dayOfWeek.includes(date.getDay());
|
|
48
|
+
}
|
|
49
|
+
if (isDateInterval(matcher)) {
|
|
50
|
+
const diffBefore = differenceInCalendarDays(matcher.before, date);
|
|
51
|
+
const diffAfter = differenceInCalendarDays(matcher.after, date);
|
|
52
|
+
const isDayBefore = diffBefore > 0;
|
|
53
|
+
const isDayAfter = diffAfter < 0;
|
|
54
|
+
const isClosedInterval = isAfter(matcher.before, matcher.after);
|
|
55
|
+
if (isClosedInterval) {
|
|
56
|
+
return isDayAfter && isDayBefore;
|
|
57
|
+
} else {
|
|
58
|
+
return isDayBefore || isDayAfter;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (isDateAfterType(matcher)) {
|
|
62
|
+
return differenceInCalendarDays(date, matcher.after) > 0;
|
|
63
|
+
}
|
|
64
|
+
if (isDateBeforeType(matcher)) {
|
|
65
|
+
return differenceInCalendarDays(matcher.before, date) > 0;
|
|
66
|
+
}
|
|
67
|
+
if (typeof matcher === 'function') {
|
|
68
|
+
return matcher(date);
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './addToRange.js';
|
|
2
|
+
export * from './dateMatchModifiers.js';
|
|
3
|
+
export * from './rangeContainsDayOfWeek.js';
|
|
4
|
+
export * from './rangeContainsModifiers.js';
|
|
5
|
+
export * from './rangeIncludesDate.js';
|
|
6
|
+
export * from './rangeOverlaps.js';
|
|
7
|
+
export * from './typeguards.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type DateLib, defaultDateLib } from '../classes/DateLib.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a date range contains one or more specified days of the week.
|
|
5
|
+
*
|
|
6
|
+
* @since 9.2.2
|
|
7
|
+
* @param range - The date range to check.
|
|
8
|
+
* @param dayOfWeek - The day(s) of the week to check for (`0-6`, where `0` is
|
|
9
|
+
* Sunday).
|
|
10
|
+
* @param dateLib - The date utility library instance.
|
|
11
|
+
* @returns `true` if the range contains the specified day(s) of the week,
|
|
12
|
+
* otherwise `false`.
|
|
13
|
+
* @group Utilities
|
|
14
|
+
*/
|
|
15
|
+
export function rangeContainsDayOfWeek(
|
|
16
|
+
range: { from: Date; to: Date },
|
|
17
|
+
dayOfWeek: number | number[],
|
|
18
|
+
dateLib: DateLib = defaultDateLib,
|
|
19
|
+
) {
|
|
20
|
+
const dayOfWeekArr = !Array.isArray(dayOfWeek) ? [dayOfWeek] : dayOfWeek;
|
|
21
|
+
let date = range.from;
|
|
22
|
+
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
|
|
23
|
+
|
|
24
|
+
// iterate at maximum one week or the total days if the range is shorter than one week
|
|
25
|
+
const totalDaysLimit = Math.min(totalDays, 6);
|
|
26
|
+
for (let i = 0; i <= totalDaysLimit; i++) {
|
|
27
|
+
if (dayOfWeekArr.includes(date.getDay())) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
date = dateLib.addDays(date, 1);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type DateLib, defaultDateLib } from '../classes/DateLib.js';
|
|
2
|
+
import type { Matcher } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
import { dateMatchModifiers } from './dateMatchModifiers.js';
|
|
5
|
+
import { rangeContainsDayOfWeek } from './rangeContainsDayOfWeek.js';
|
|
6
|
+
import { rangeIncludesDate } from './rangeIncludesDate.js';
|
|
7
|
+
import { rangeOverlaps } from './rangeOverlaps.js';
|
|
8
|
+
import {
|
|
9
|
+
isDateAfterType,
|
|
10
|
+
isDateBeforeType,
|
|
11
|
+
isDateInterval,
|
|
12
|
+
isDateRange,
|
|
13
|
+
isDatesArray,
|
|
14
|
+
isDayOfWeekType,
|
|
15
|
+
} from './typeguards.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a date range contains dates that match the given modifiers.
|
|
19
|
+
*
|
|
20
|
+
* @since 9.2.2
|
|
21
|
+
* @param range - The date range to check.
|
|
22
|
+
* @param modifiers - The modifiers to match against.
|
|
23
|
+
* @param dateLib - The date utility library instance.
|
|
24
|
+
* @returns `true` if the range contains matching dates, otherwise `false`.
|
|
25
|
+
* @group Utilities
|
|
26
|
+
*/
|
|
27
|
+
export function rangeContainsModifiers(
|
|
28
|
+
range: { from: Date; to: Date },
|
|
29
|
+
modifiers: Matcher | Matcher[],
|
|
30
|
+
dateLib: DateLib = defaultDateLib,
|
|
31
|
+
): boolean {
|
|
32
|
+
const matchers = Array.isArray(modifiers) ? modifiers : [modifiers];
|
|
33
|
+
|
|
34
|
+
// Defer function matchers evaluation as they are the least performant.
|
|
35
|
+
const nonFunctionMatchers = matchers.filter((matcher) => typeof matcher !== 'function');
|
|
36
|
+
|
|
37
|
+
const nonFunctionMatchersResult = nonFunctionMatchers.some((matcher) => {
|
|
38
|
+
if (typeof matcher === 'boolean') return matcher;
|
|
39
|
+
|
|
40
|
+
if (dateLib.isDate(matcher)) {
|
|
41
|
+
return rangeIncludesDate(range, matcher, false, dateLib);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isDatesArray(matcher, dateLib)) {
|
|
45
|
+
return matcher.some((date) => rangeIncludesDate(range, date, false, dateLib));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isDateRange(matcher)) {
|
|
49
|
+
if (matcher.from && matcher.to) {
|
|
50
|
+
return rangeOverlaps(range, { from: matcher.from, to: matcher.to }, dateLib);
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isDayOfWeekType(matcher)) {
|
|
56
|
+
return rangeContainsDayOfWeek(range, matcher.dayOfWeek, dateLib);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (isDateInterval(matcher)) {
|
|
60
|
+
const isClosedInterval = dateLib.isAfter(matcher.before, matcher.after);
|
|
61
|
+
if (isClosedInterval) {
|
|
62
|
+
return rangeOverlaps(
|
|
63
|
+
range,
|
|
64
|
+
{
|
|
65
|
+
from: dateLib.addDays(matcher.after, 1),
|
|
66
|
+
to: dateLib.addDays(matcher.before, -1),
|
|
67
|
+
},
|
|
68
|
+
dateLib,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return (
|
|
72
|
+
dateMatchModifiers(range.from, matcher, dateLib) ||
|
|
73
|
+
dateMatchModifiers(range.to, matcher, dateLib)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (isDateAfterType(matcher) || isDateBeforeType(matcher)) {
|
|
78
|
+
return (
|
|
79
|
+
dateMatchModifiers(range.from, matcher, dateLib) ||
|
|
80
|
+
dateMatchModifiers(range.to, matcher, dateLib)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return false;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (nonFunctionMatchersResult) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const functionMatchers = matchers.filter((matcher) => typeof matcher === 'function');
|
|
92
|
+
|
|
93
|
+
if (functionMatchers.length) {
|
|
94
|
+
let date = range.from;
|
|
95
|
+
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
98
|
+
if (functionMatchers.some((matcher) => matcher(date))) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
date = dateLib.addDays(date, 1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defaultDateLib } from '../classes/index.js';
|
|
2
|
+
import type { DateRange } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given date is within a specified date range.
|
|
6
|
+
*
|
|
7
|
+
* @since 9.0.0
|
|
8
|
+
* @param range - The date range to check against.
|
|
9
|
+
* @param date - The date to check.
|
|
10
|
+
* @param excludeEnds - If `true`, the range's start and end dates are excluded.
|
|
11
|
+
* @param dateLib - The date utility library instance.
|
|
12
|
+
* @returns `true` if the date is within the range, otherwise `false`.
|
|
13
|
+
* @group Utilities
|
|
14
|
+
*/
|
|
15
|
+
export function rangeIncludesDate(
|
|
16
|
+
range: DateRange,
|
|
17
|
+
date: Date,
|
|
18
|
+
excludeEnds = false,
|
|
19
|
+
dateLib = defaultDateLib,
|
|
20
|
+
): boolean {
|
|
21
|
+
let { from, to } = range;
|
|
22
|
+
const { differenceInCalendarDays, isSameDay } = dateLib;
|
|
23
|
+
if (from && to) {
|
|
24
|
+
const isRangeInverted = differenceInCalendarDays(to, from) < 0;
|
|
25
|
+
if (isRangeInverted) {
|
|
26
|
+
[from, to] = [to, from];
|
|
27
|
+
}
|
|
28
|
+
const isInRange =
|
|
29
|
+
differenceInCalendarDays(date, from) >= (excludeEnds ? 1 : 0) &&
|
|
30
|
+
differenceInCalendarDays(to, date) >= (excludeEnds ? 1 : 0);
|
|
31
|
+
return isInRange;
|
|
32
|
+
}
|
|
33
|
+
if (!excludeEnds && to) {
|
|
34
|
+
return isSameDay(to, date);
|
|
35
|
+
}
|
|
36
|
+
if (!excludeEnds && from) {
|
|
37
|
+
return isSameDay(from, date);
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defaultDateLib } from '../classes/index.js';
|
|
2
|
+
|
|
3
|
+
import { rangeIncludesDate } from './rangeIncludesDate.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Determines if two date ranges overlap.
|
|
7
|
+
*
|
|
8
|
+
* @since 9.2.2
|
|
9
|
+
* @param rangeLeft - The first date range.
|
|
10
|
+
* @param rangeRight - The second date range.
|
|
11
|
+
* @param dateLib - The date utility library instance.
|
|
12
|
+
* @returns `true` if the ranges overlap, otherwise `false`.
|
|
13
|
+
* @group Utilities
|
|
14
|
+
*/
|
|
15
|
+
export function rangeOverlaps(
|
|
16
|
+
rangeLeft: { from: Date; to: Date },
|
|
17
|
+
rangeRight: { from: Date; to: Date },
|
|
18
|
+
dateLib = defaultDateLib,
|
|
19
|
+
): boolean {
|
|
20
|
+
return (
|
|
21
|
+
rangeIncludesDate(rangeLeft, rangeRight.from, false, dateLib) ||
|
|
22
|
+
rangeIncludesDate(rangeLeft, rangeRight.to, false, dateLib) ||
|
|
23
|
+
rangeIncludesDate(rangeRight, rangeLeft.from, false, dateLib) ||
|
|
24
|
+
rangeIncludesDate(rangeRight, rangeLeft.to, false, dateLib)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TZDate } from '@date-fns/tz';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert a {@link Date} or {@link TZDate} instance to the given time zone.
|
|
5
|
+
* Reuses the same instance when it is already a {@link TZDate} using the target
|
|
6
|
+
* time zone to avoid extra allocations.
|
|
7
|
+
*/
|
|
8
|
+
export function toTimeZone(date: Date, timeZone: string): TZDate {
|
|
9
|
+
if (date instanceof TZDate && date.timeZone === timeZone) {
|
|
10
|
+
return date;
|
|
11
|
+
}
|
|
12
|
+
return new TZDate(date, timeZone);
|
|
13
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { DateLib } from '../classes/DateLib.js';
|
|
2
|
+
import type { DateAfter, DateBefore, DateInterval, DateRange, DayOfWeek } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given value is of type {@link DateInterval}.
|
|
6
|
+
*
|
|
7
|
+
* @param matcher - The value to check.
|
|
8
|
+
* @returns `true` if the value is a {@link DateInterval}, otherwise `false`.
|
|
9
|
+
* @group Utilities
|
|
10
|
+
*/
|
|
11
|
+
export function isDateInterval(matcher: unknown): matcher is DateInterval {
|
|
12
|
+
return Boolean(
|
|
13
|
+
matcher && typeof matcher === 'object' && 'before' in matcher && 'after' in matcher,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the given value is of type {@link DateRange}.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The value to check.
|
|
21
|
+
* @returns `true` if the value is a {@link DateRange}, otherwise `false`.
|
|
22
|
+
* @group Utilities
|
|
23
|
+
*/
|
|
24
|
+
export function isDateRange(value: unknown): value is DateRange {
|
|
25
|
+
return Boolean(value && typeof value === 'object' && 'from' in value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the given value is of type {@link DateAfter}.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The value to check.
|
|
32
|
+
* @returns `true` if the value is a {@link DateAfter}, otherwise `false`.
|
|
33
|
+
* @group Utilities
|
|
34
|
+
*/
|
|
35
|
+
export function isDateAfterType(value: unknown): value is DateAfter {
|
|
36
|
+
return Boolean(value && typeof value === 'object' && 'after' in value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the given value is of type {@link DateBefore}.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check.
|
|
43
|
+
* @returns `true` if the value is a {@link DateBefore}, otherwise `false`.
|
|
44
|
+
* @group Utilities
|
|
45
|
+
*/
|
|
46
|
+
export function isDateBeforeType(value: unknown): value is DateBefore {
|
|
47
|
+
return Boolean(value && typeof value === 'object' && 'before' in value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the given value is of type {@link DayOfWeek}.
|
|
52
|
+
*
|
|
53
|
+
* @param value - The value to check.
|
|
54
|
+
* @returns `true` if the value is a {@link DayOfWeek}, otherwise `false`.
|
|
55
|
+
* @group Utilities
|
|
56
|
+
*/
|
|
57
|
+
export function isDayOfWeekType(value: unknown): value is DayOfWeek {
|
|
58
|
+
return Boolean(value && typeof value === 'object' && 'dayOfWeek' in value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the given value is an array of valid dates.
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
* @param value - The value to check.
|
|
66
|
+
* @param dateLib - The date utility library instance.
|
|
67
|
+
* @returns `true` if the value is an array of valid dates, otherwise `false`.
|
|
68
|
+
*/
|
|
69
|
+
export function isDatesArray(value: unknown, dateLib: DateLib): value is Date[] {
|
|
70
|
+
return Array.isArray(value) && value.every(dateLib.isDate);
|
|
71
|
+
}
|
package/status.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"upstream": {
|
|
3
|
+
"package": "react-day-picker",
|
|
4
|
+
"version": "10.0.1",
|
|
5
|
+
"commit": "6d3929d655779d178638d8f80171597a579468e8"
|
|
6
|
+
},
|
|
7
|
+
"surface": "DayPicker, public components, hooks, date classes, helpers, labels, formatters, locales, styles, and public types.",
|
|
8
|
+
"divergences": [
|
|
9
|
+
"React DOM prop types are preserved publicly and normalized at Octane render boundaries."
|
|
10
|
+
],
|
|
11
|
+
"ssr": "Calendar markup and accessibility attributes render without browser globals.",
|
|
12
|
+
"verified": "2026-08-02"
|
|
13
|
+
}
|