@knitui/dates 0.5.0 → 0.6.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/lib/commonjs/DatesProvider/DatesProvider.js +33 -4
- package/lib/commonjs/DatesProvider/DatesProvider.js.map +1 -1
- package/lib/commonjs/Day/Day.js +45 -7
- package/lib/commonjs/Day/Day.js.map +1 -1
- package/lib/commonjs/Month/Month.js +266 -80
- package/lib/commonjs/Month/Month.js.map +1 -1
- package/lib/commonjs/MonthLevel/MonthLevel.js +19 -3
- package/lib/commonjs/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/commonjs/MonthsList/MonthsList.js +160 -60
- package/lib/commonjs/MonthsList/MonthsList.js.map +1 -1
- package/lib/commonjs/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js +7 -1
- package/lib/commonjs/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js +15 -1
- package/lib/commonjs/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/commonjs/TimeControlsList/TimeControlsList.js +16 -3
- package/lib/commonjs/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js +23 -4
- package/lib/commonjs/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/commonjs/YearsList/YearsList.js +155 -60
- package/lib/commonjs/YearsList/YearsList.js.map +1 -1
- package/lib/commonjs/YearsList/get-year-in-tab-order/get-year-in-tab-order.js +7 -1
- package/lib/commonjs/YearsList/get-year-in-tab-order/get-year-in-tab-order.js.map +1 -1
- package/lib/commonjs/hooks/use-dates-state/is-in-range/is-in-range.js +20 -0
- package/lib/commonjs/hooks/use-dates-state/is-in-range/is-in-range.js.map +1 -1
- package/lib/commonjs/hooks/use-dates-state/use-dates-state.js +25 -7
- package/lib/commonjs/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/lib/commonjs/internal/are-cell-props-equal.js +64 -0
- package/lib/commonjs/internal/are-cell-props-equal.js.map +1 -0
- package/lib/commonjs/internal/date-string-fast-path.js +98 -0
- package/lib/commonjs/internal/date-string-fast-path.js.map +1 -0
- package/lib/commonjs/internal/memoize-control-props.js +54 -0
- package/lib/commonjs/internal/memoize-control-props.js.map +1 -0
- package/lib/commonjs/internal/month-days-cache.js +71 -0
- package/lib/commonjs/internal/month-days-cache.js.map +1 -0
- package/lib/commonjs/utils/get-date-in-tab-order/get-date-in-tab-order.js +9 -1
- package/lib/commonjs/utils/get-date-in-tab-order/get-date-in-tab-order.js.map +1 -1
- package/lib/commonjs/utils/is-after-min-date/is-after-min-date.js +14 -1
- package/lib/commonjs/utils/is-after-min-date/is-after-min-date.js.map +1 -1
- package/lib/commonjs/utils/is-before-max-date/is-before-max-date.js +14 -1
- package/lib/commonjs/utils/is-before-max-date/is-before-max-date.js.map +1 -1
- package/lib/commonjs/utils/is-same-month/is-same-month.js +17 -1
- package/lib/commonjs/utils/is-same-month/is-same-month.js.map +1 -1
- package/lib/module/DatesProvider/DatesProvider.js +34 -5
- package/lib/module/DatesProvider/DatesProvider.js.map +1 -1
- package/lib/module/Day/Day.js +46 -8
- package/lib/module/Day/Day.js.map +1 -1
- package/lib/module/Month/Month.js +267 -82
- package/lib/module/Month/Month.js.map +1 -1
- package/lib/module/MonthLevel/MonthLevel.js +19 -3
- package/lib/module/MonthLevel/MonthLevel.js.map +1 -1
- package/lib/module/MonthsList/MonthsList.js +159 -60
- package/lib/module/MonthsList/MonthsList.js.map +1 -1
- package/lib/module/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js +7 -1
- package/lib/module/MonthsList/get-month-in-tab-order/get-month-in-tab-order.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControl.js +15 -1
- package/lib/module/TimeControlsList/TimeControl.js.map +1 -1
- package/lib/module/TimeControlsList/TimeControlsList.js +16 -3
- package/lib/module/TimeControlsList/TimeControlsList.js.map +1 -1
- package/lib/module/WeekdaysRow/WeekdaysRow.js +23 -4
- package/lib/module/WeekdaysRow/WeekdaysRow.js.map +1 -1
- package/lib/module/YearsList/YearsList.js +154 -60
- package/lib/module/YearsList/YearsList.js.map +1 -1
- package/lib/module/YearsList/get-year-in-tab-order/get-year-in-tab-order.js +7 -1
- package/lib/module/YearsList/get-year-in-tab-order/get-year-in-tab-order.js.map +1 -1
- package/lib/module/hooks/use-dates-state/is-in-range/is-in-range.js +20 -0
- package/lib/module/hooks/use-dates-state/is-in-range/is-in-range.js.map +1 -1
- package/lib/module/hooks/use-dates-state/use-dates-state.js +25 -7
- package/lib/module/hooks/use-dates-state/use-dates-state.js.map +1 -1
- package/lib/module/internal/are-cell-props-equal.js +60 -0
- package/lib/module/internal/are-cell-props-equal.js.map +1 -0
- package/lib/module/internal/date-string-fast-path.js +91 -0
- package/lib/module/internal/date-string-fast-path.js.map +1 -0
- package/lib/module/internal/memoize-control-props.js +50 -0
- package/lib/module/internal/memoize-control-props.js.map +1 -0
- package/lib/module/internal/month-days-cache.js +68 -0
- package/lib/module/internal/month-days-cache.js.map +1 -0
- package/lib/module/utils/get-date-in-tab-order/get-date-in-tab-order.js +9 -1
- package/lib/module/utils/get-date-in-tab-order/get-date-in-tab-order.js.map +1 -1
- package/lib/module/utils/is-after-min-date/is-after-min-date.js +14 -1
- package/lib/module/utils/is-after-min-date/is-after-min-date.js.map +1 -1
- package/lib/module/utils/is-before-max-date/is-before-max-date.js +14 -1
- package/lib/module/utils/is-before-max-date/is-before-max-date.js.map +1 -1
- package/lib/module/utils/is-same-month/is-same-month.js +17 -1
- package/lib/module/utils/is-same-month/is-same-month.js.map +1 -1
- package/lib/typescript/Calendar/pick-calendar-props/pick-calendar-props.d.ts +1 -1
- package/lib/typescript/CalendarHeader/CalendarHeader.d.ts +14 -14
- package/lib/typescript/DatesProvider/DatesProvider.d.ts.map +1 -1
- package/lib/typescript/Day/Day.d.ts +31 -31
- package/lib/typescript/Day/Day.d.ts.map +1 -1
- package/lib/typescript/DecadeLevel/DecadeLevel.d.ts +7 -7
- package/lib/typescript/DecadeLevelGroup/DecadeLevelGroup.d.ts +7 -7
- package/lib/typescript/InlineDateTimePicker/InlineDateTimePicker.d.ts +4 -4
- package/lib/typescript/MiniCalendar/MiniCalendar.d.ts +18 -18
- package/lib/typescript/Month/Month.d.ts +9 -8
- package/lib/typescript/Month/Month.d.ts.map +1 -1
- package/lib/typescript/MonthLevel/MonthLevel.d.ts +10 -10
- package/lib/typescript/MonthLevel/MonthLevel.d.ts.map +1 -1
- package/lib/typescript/MonthLevelGroup/MonthLevelGroup.d.ts +10 -10
- package/lib/typescript/MonthsList/MonthsList.d.ts +3 -2
- package/lib/typescript/MonthsList/MonthsList.d.ts.map +1 -1
- package/lib/typescript/MonthsList/get-month-in-tab-order/get-month-in-tab-order.d.ts +6 -0
- package/lib/typescript/MonthsList/get-month-in-tab-order/get-month-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/PickerControl/PickerControl.d.ts +10 -10
- package/lib/typescript/TimeControlsList/TimeControl.d.ts +13 -0
- package/lib/typescript/TimeControlsList/TimeControl.d.ts.map +1 -1
- package/lib/typescript/TimeControlsList/TimeControlsList.d.ts.map +1 -1
- package/lib/typescript/TimeGrid/TimeGrid.d.ts +7 -7
- package/lib/typescript/TimePicker/TimePicker.d.ts +4 -4
- package/lib/typescript/TimePresets/TimePresetGroup.d.ts +4 -4
- package/lib/typescript/TimePresets/TimePresets.d.ts +6 -4
- package/lib/typescript/TimePresets/TimePresets.d.ts.map +1 -1
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts +6 -6
- package/lib/typescript/WeekdaysRow/WeekdaysRow.d.ts.map +1 -1
- package/lib/typescript/YearLevel/YearLevel.d.ts +7 -7
- package/lib/typescript/YearLevelGroup/YearLevelGroup.d.ts +7 -7
- package/lib/typescript/YearsList/YearsList.d.ts +3 -2
- package/lib/typescript/YearsList/YearsList.d.ts.map +1 -1
- package/lib/typescript/YearsList/get-year-in-tab-order/get-year-in-tab-order.d.ts +6 -0
- package/lib/typescript/YearsList/get-year-in-tab-order/get-year-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/_reference/ExampleControl.d.ts +8 -8
- package/lib/typescript/hooks/use-dates-state/is-in-range/is-in-range.d.ts +12 -0
- package/lib/typescript/hooks/use-dates-state/is-in-range/is-in-range.d.ts.map +1 -1
- package/lib/typescript/hooks/use-dates-state/use-dates-state.d.ts.map +1 -1
- package/lib/typescript/internal/are-cell-props-equal.d.ts +21 -0
- package/lib/typescript/internal/are-cell-props-equal.d.ts.map +1 -0
- package/lib/typescript/internal/date-string-fast-path.d.ts +35 -0
- package/lib/typescript/internal/date-string-fast-path.d.ts.map +1 -0
- package/lib/typescript/internal/memoize-control-props.d.ts +12 -0
- package/lib/typescript/internal/memoize-control-props.d.ts.map +1 -0
- package/lib/typescript/internal/month-days-cache.d.ts +19 -0
- package/lib/typescript/internal/month-days-cache.d.ts.map +1 -0
- package/lib/typescript/utils/get-date-in-tab-order/get-date-in-tab-order.d.ts +9 -1
- package/lib/typescript/utils/get-date-in-tab-order/get-date-in-tab-order.d.ts.map +1 -1
- package/lib/typescript/utils/is-after-min-date/is-after-min-date.d.ts +6 -0
- package/lib/typescript/utils/is-after-min-date/is-after-min-date.d.ts.map +1 -1
- package/lib/typescript/utils/is-before-max-date/is-before-max-date.d.ts +6 -0
- package/lib/typescript/utils/is-before-max-date/is-before-max-date.d.ts.map +1 -1
- package/lib/typescript/utils/is-same-month/is-same-month.d.ts +13 -1
- package/lib/typescript/utils/is-same-month/is-same-month.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/DatesProvider/DatesProvider.tsx +27 -5
- package/src/Day/Day.tsx +51 -10
- package/src/Month/Month.tsx +357 -80
- package/src/MonthLevel/MonthLevel.tsx +35 -16
- package/src/MonthsList/MonthsList.tsx +201 -55
- package/src/MonthsList/get-month-in-tab-order/get-month-in-tab-order.ts +12 -1
- package/src/TimeControlsList/TimeControl.tsx +16 -1
- package/src/TimeControlsList/TimeControlsList.tsx +15 -3
- package/src/WeekdaysRow/WeekdaysRow.tsx +29 -5
- package/src/YearsList/YearsList.tsx +196 -55
- package/src/YearsList/get-year-in-tab-order/get-year-in-tab-order.ts +12 -1
- package/src/hooks/use-dates-state/is-in-range/is-in-range.ts +22 -0
- package/src/hooks/use-dates-state/use-dates-state.ts +27 -11
- package/src/internal/are-cell-props-equal.ts +63 -0
- package/src/internal/date-string-fast-path.ts +94 -0
- package/src/internal/memoize-control-props.ts +54 -0
- package/src/internal/month-days-cache.ts +77 -0
- package/src/utils/get-date-in-tab-order/get-date-in-tab-order.ts +17 -2
- package/src/utils/is-after-min-date/is-after-min-date.ts +16 -1
- package/src/utils/is-before-max-date/is-before-max-date.ts +16 -1
- package/src/utils/is-same-month/is-same-month.ts +18 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Internal cross-platform helper — NOT exported from the public `src/index.ts`
|
|
2
|
+
// barrel.
|
|
3
|
+
//
|
|
4
|
+
// `getMonthDays` is the grid's enumerator, and it is not cheap: it walks the
|
|
5
|
+
// month day by day, so a 5-week grid costs ~70 dayjs instances (the running
|
|
6
|
+
// cursor plus dayjs' internal clones) and 35 `format("YYYY-MM-DD")` calls. The
|
|
7
|
+
// answer, though, is a PURE function of three primitives — the month, the first
|
|
8
|
+
// weekday, and whether the grid is padded to 6 weeks — and it is re-derived on
|
|
9
|
+
// every single `Month` render, including the ones triggered by nothing but a web
|
|
10
|
+
// hover moving one cell over.
|
|
11
|
+
//
|
|
12
|
+
// A small module-level LRU makes month navigation free after the first visit:
|
|
13
|
+
// stepping back and forth across a few months (or re-rendering the same month
|
|
14
|
+
// for any other reason) replays cached arrays instead of re-walking the calendar.
|
|
15
|
+
// The cap is generous enough to hold a couple of years of browsing yet bounded so
|
|
16
|
+
// a long-lived app cannot grow the map without limit.
|
|
17
|
+
//
|
|
18
|
+
// This deliberately wraps the public `getMonthDays` rather than caching inside
|
|
19
|
+
// it: the public util keeps returning a FRESH array per call, so an external
|
|
20
|
+
// consumer that mutates the result cannot corrupt a shared cache entry. Inside
|
|
21
|
+
// this package the arrays are only read (`.flat()`, `.filter()`, `.find()`,
|
|
22
|
+
// `.map()`), so sharing them is safe — and it additionally gives the grid a
|
|
23
|
+
// STABLE array identity per month, which is what lets `Month` use it directly as
|
|
24
|
+
// a `useMemo` dependency.
|
|
25
|
+
|
|
26
|
+
import type { DateStringValue, DayOfWeek } from "../types";
|
|
27
|
+
import { getMonthDays } from "../utils";
|
|
28
|
+
|
|
29
|
+
/** How many distinct month grids to retain (~2 years of navigation). */
|
|
30
|
+
const MAX_ENTRIES = 32;
|
|
31
|
+
|
|
32
|
+
const cache = new Map<string, DateStringValue[][]>();
|
|
33
|
+
|
|
34
|
+
interface CachedMonthDaysInput {
|
|
35
|
+
/** Any date within the month to enumerate, `YYYY-MM-DD`. */
|
|
36
|
+
month: DateStringValue;
|
|
37
|
+
/** First weekday of each row. */
|
|
38
|
+
firstDayOfWeek: DayOfWeek;
|
|
39
|
+
/** Pad to a fixed 6 weeks so the grid height never shifts. */
|
|
40
|
+
consistentWeeks: boolean | undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `getMonthDays` memoized on its three primitive inputs.
|
|
45
|
+
*
|
|
46
|
+
* The returned weeks array is SHARED — treat it as read-only. Callers also get a
|
|
47
|
+
* stable identity for a given key, so it can be passed straight to `useMemo` as a
|
|
48
|
+
* dependency.
|
|
49
|
+
*/
|
|
50
|
+
export function getCachedMonthDays({
|
|
51
|
+
month,
|
|
52
|
+
firstDayOfWeek,
|
|
53
|
+
consistentWeeks,
|
|
54
|
+
}: CachedMonthDaysInput): DateStringValue[][] {
|
|
55
|
+
const key = `${month}|${firstDayOfWeek}|${consistentWeeks ? 1 : 0}`;
|
|
56
|
+
const cached = cache.get(key);
|
|
57
|
+
|
|
58
|
+
if (cached) {
|
|
59
|
+
// Re-insert so the most recently used key is last, making the first map key
|
|
60
|
+
// the least recently used one for eviction below.
|
|
61
|
+
cache.delete(key);
|
|
62
|
+
cache.set(key, cached);
|
|
63
|
+
return cached;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const weeks = getMonthDays({ month, firstDayOfWeek, consistentWeeks });
|
|
67
|
+
cache.set(key, weeks);
|
|
68
|
+
|
|
69
|
+
if (cache.size > MAX_ENTRIES) {
|
|
70
|
+
const oldest = cache.keys().next();
|
|
71
|
+
if (!oldest.done) {
|
|
72
|
+
cache.delete(oldest.value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return weeks;
|
|
77
|
+
}
|
|
@@ -13,7 +13,15 @@ interface GetDateInTabOrderInput {
|
|
|
13
13
|
minDate: DateStringValue | undefined;
|
|
14
14
|
/** Upper bound, `YYYY-MM-DD`. */
|
|
15
15
|
maxDate: DateStringValue | undefined;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Per-day prop getter — its `disabled`/`selected` participate in the choice.
|
|
18
|
+
*
|
|
19
|
+
* It is consulted TWICE per date below (once for `disabled`, once for
|
|
20
|
+
* `selected`), so callers should pass a getter wrapped in
|
|
21
|
+
* `memoizeByDate` — the same wrapper they use for their own cell loop, so the
|
|
22
|
+
* whole render resolves each date's props exactly once. See
|
|
23
|
+
* `internal/memoize-control-props.ts`.
|
|
24
|
+
*/
|
|
17
25
|
getDayProps: ((date: DateStringValue) => Partial<DayProps>) | undefined;
|
|
18
26
|
/** Predicate marking a day disabled. */
|
|
19
27
|
excludeDate: ((date: DateStringValue) => boolean) | undefined;
|
|
@@ -54,7 +62,14 @@ export function getDateInTabOrder({
|
|
|
54
62
|
return selectedDate;
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
// `dayjs().isSame(date, "date")` inside the predicate built a FRESH "now"
|
|
66
|
+
// instance (plus dayjs' internal `startOf`/`endOf` clones) for every candidate
|
|
67
|
+
// — ~4 allocations × up to 42 dates, to answer a question whose left-hand side
|
|
68
|
+
// never changes. One formatted "today" string compares exactly instead:
|
|
69
|
+
// `dates` always comes from `getMonthDays`, which emits zero-padded
|
|
70
|
+
// `YYYY-MM-DD`, so string equality is equivalent to a day-granularity `isSame`.
|
|
71
|
+
const today = dayjs().format("YYYY-MM-DD");
|
|
72
|
+
const currentDate = enabledDates.find((date) => date.slice(0, 10) === today);
|
|
58
73
|
|
|
59
74
|
if (currentDate) {
|
|
60
75
|
return currentDate;
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
|
|
3
|
+
import { isCanonicalDateString } from "../../internal/date-string-fast-path";
|
|
3
4
|
import type { DateStringValue } from "../../types";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Whether `date` is on or after `minDate` (no lower bound when `minDate` is
|
|
7
8
|
* absent). Mirrors @mantine/dates `isAfterMinDate`.
|
|
9
|
+
*
|
|
10
|
+
* The lower-bound twin of `isBeforeMaxDate` — the dayjs spelling
|
|
11
|
+
* (`isAfter(minDate - 1 day, "day")`) is a day-granularity `>=`, exactly a
|
|
12
|
+
* lexicographic `>=` for canonical zero-padded `YYYY-MM-DD` strings. Same hot
|
|
13
|
+
* path (once per cell in `Month`, again in `getDateInTabOrder`), same fallback
|
|
14
|
+
* for non-canonical input.
|
|
8
15
|
*/
|
|
9
16
|
export function isAfterMinDate(
|
|
10
17
|
date: DateStringValue,
|
|
11
18
|
minDate: DateStringValue | undefined,
|
|
12
19
|
): boolean {
|
|
13
|
-
|
|
20
|
+
if (!minDate) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (isCanonicalDateString(date) && isCanonicalDateString(minDate)) {
|
|
25
|
+
return date.slice(0, 10) >= minDate.slice(0, 10);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return dayjs(date).isAfter(dayjs(minDate).subtract(1, "day"), "day");
|
|
14
29
|
}
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
|
|
3
|
+
import { isCanonicalDateString } from "../../internal/date-string-fast-path";
|
|
3
4
|
import type { DateStringValue } from "../../types";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Whether `date` is on or before `maxDate` (no upper bound when `maxDate` is
|
|
7
8
|
* absent). Mirrors @mantine/dates `isBeforeMaxDate`.
|
|
9
|
+
*
|
|
10
|
+
* Called once per cell by `Month` and again by `getDateInTabOrder`. The dayjs
|
|
11
|
+
* spelling (`isBefore(maxDate + 1 day, "day")`) is a day-granularity `<=`, which
|
|
12
|
+
* for canonical zero-padded `YYYY-MM-DD` strings is exactly a lexicographic
|
|
13
|
+
* `<=` — same answer, no `add`, no clones, no allocations. Non-canonical input
|
|
14
|
+
* falls back to the original path.
|
|
8
15
|
*/
|
|
9
16
|
export function isBeforeMaxDate(
|
|
10
17
|
date: DateStringValue,
|
|
11
18
|
maxDate: DateStringValue | undefined,
|
|
12
19
|
): boolean {
|
|
13
|
-
|
|
20
|
+
if (!maxDate) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (isCanonicalDateString(date) && isCanonicalDateString(maxDate)) {
|
|
25
|
+
return date.slice(0, 10) <= maxDate.slice(0, 10);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return dayjs(date).isBefore(dayjs(maxDate).add(1, "day"), "day");
|
|
14
29
|
}
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
|
|
3
|
+
import { isCanonicalYearMonthString } from "../../internal/date-string-fast-path";
|
|
3
4
|
import type { DateStringValue } from "../../types";
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Whether two dates fall in the same calendar month. Mirrors @mantine/dates
|
|
8
|
+
* `isSameMonth`.
|
|
9
|
+
*
|
|
10
|
+
* This is one of the hottest comparisons in the package — `Month` calls it once
|
|
11
|
+
* per cell (42×) to decide `outside`, and `getDateInTabOrder` calls it again per
|
|
12
|
+
* cell whenever `hideOutsideDates` is on (which `DatePicker` enables
|
|
13
|
+
* automatically for multiple columns). The dayjs spelling cost 2 instances plus
|
|
14
|
+
* 2 `format("YYYY-MM")` calls (locale lookup + regex replace) EACH TIME; for the
|
|
15
|
+
* canonical `YYYY-MM-DD` strings that are the actual inputs, comparing the
|
|
16
|
+
* `YYYY-MM` prefix is exact and allocates nothing. `Date` inputs (and any
|
|
17
|
+
* non-canonical string) keep the original dayjs path.
|
|
18
|
+
*/
|
|
6
19
|
export function isSameMonth(
|
|
7
20
|
date: DateStringValue | Date,
|
|
8
21
|
comparison: DateStringValue | Date,
|
|
9
22
|
): boolean {
|
|
23
|
+
if (isCanonicalYearMonthString(date) && isCanonicalYearMonthString(comparison)) {
|
|
24
|
+
return date.slice(0, 7) === comparison.slice(0, 7);
|
|
25
|
+
}
|
|
26
|
+
|
|
10
27
|
return dayjs(date).format("YYYY-MM") === dayjs(comparison).format("YYYY-MM");
|
|
11
28
|
}
|