@klinking/colander 3.1.0-alpha.6 → 3.1.0-alpha.8
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/formats/date.cjs +2 -3
- package/dist/formats/date.d.cts +10 -14
- package/dist/formats/date.d.mts +10 -14
- package/dist/formats/date.mjs +2 -3
- package/dist/formats/object.cjs +2 -3
- package/dist/formats/object.d.cts +10 -14
- package/dist/formats/object.d.mts +10 -14
- package/dist/formats/object.mjs +2 -3
- package/dist/formats/plain-date-time.cjs +2 -3
- package/dist/formats/plain-date-time.d.cts +10 -14
- package/dist/formats/plain-date-time.d.mts +10 -14
- package/dist/formats/plain-date-time.mjs +2 -3
- package/dist/formats/plain-date.cjs +2 -3
- package/dist/formats/plain-date.d.cts +10 -14
- package/dist/formats/plain-date.d.mts +10 -14
- package/dist/formats/plain-date.mjs +2 -3
- package/dist/formats/plain-month-day.cjs +2 -3
- package/dist/formats/plain-month-day.d.cts +10 -14
- package/dist/formats/plain-month-day.d.mts +10 -14
- package/dist/formats/plain-month-day.mjs +2 -3
- package/dist/formats/plain-year-month.cjs +2 -3
- package/dist/formats/plain-year-month.d.cts +10 -14
- package/dist/formats/plain-year-month.d.mts +10 -14
- package/dist/formats/plain-year-month.mjs +2 -3
- package/dist/formats/zoned-date-time.cjs +2 -3
- package/dist/formats/zoned-date-time.d.cts +10 -14
- package/dist/formats/zoned-date-time.d.mts +10 -14
- package/dist/formats/zoned-date-time.mjs +2 -3
- package/dist/{index-DnFCKyyw.d.cts → index-BqzrxYgn.d.cts} +106 -116
- package/dist/{index-q3cQKJdA.d.mts → index-CkhYFmf4.d.mts} +106 -116
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -2
- package/dist/{weeks-navigation-Dn3UtG76.mjs → weeks-navigation-BWB5OvqW.mjs} +151 -188
- package/dist/{weeks-navigation-SuKJZJCM.cjs → weeks-navigation-CatYJIKb.cjs} +153 -191
- package/package.json +17 -18
- package/src/calendar-provider.test.tsx +1 -1
- package/src/compute-weeks-in-window.test.ts +1 -1
- package/src/day-cell-state.test.ts +1 -1
- package/src/day-cell.test.tsx +1 -1
- package/src/formats/formats.test.ts +1 -1
- package/src/grid.event-perf.test.tsx +7 -1
- package/src/grid.perf.test.tsx +7 -1
- package/src/grid.tsx +1 -1
- package/src/keyboard.test.ts +1 -1
- package/src/month-separator.test.tsx +1 -1
- package/src/month-view.bounds.test.tsx +1 -1
- package/src/month-view.test.tsx +89 -1
- package/src/month-view.tsx +14 -5
- package/src/month-window.test.ts +1 -1
- package/src/out-of-range.test.ts +34 -54
- package/src/out-of-range.ts +47 -123
- package/src/range-preview.test.ts +1 -1
- package/src/resolve-first-week.test.ts +1 -1
- package/src/today.test.tsx +8 -1
- package/src/utils.bench.ts +158 -106
- package/src/utils.test.ts +1 -1
- package/src/view-context.test.tsx +1 -1
- package/src/weeks-keyboard.test.ts +1 -1
- package/src/weeks-navigation.tsx +15 -6
- package/src/weeks-view-state.ts +21 -12
- package/src/weeks-view.bounds.test.tsx +246 -0
- package/src/weeks-view.test.tsx +1 -1
- package/src/weeks-window.test.ts +110 -22
- package/src/weeks-window.ts +57 -19
package/src/out-of-range.ts
CHANGED
|
@@ -12,7 +12,8 @@ import type { TemporalNamespace, WeekStartDay } from "./types";
|
|
|
12
12
|
* - `"unbounded"` — Navigation is never restricted by `min`/`max`; any range of
|
|
13
13
|
* weeks can be viewed. Out-of-range days simply render disabled. (Default.)
|
|
14
14
|
* - `"stop"` — Navigation halts at the boundary: the Prev/Next button is
|
|
15
|
-
* disabled
|
|
15
|
+
* disabled, and `goNext`/`goPrev`/`scrollToWeek` and keyboard paging do
|
|
16
|
+
* nothing, once the next step would show a window containing no in-range day.
|
|
16
17
|
* - `"stop-shrink"` — Like `"stop"`, but near the edge the window **shrinks** to
|
|
17
18
|
* fewer week rows instead of showing rows that are entirely out of range.
|
|
18
19
|
* - `"snap"` — A jump that would overshoot **snaps** the window so its edge
|
|
@@ -20,6 +21,8 @@ import type { TemporalNamespace, WeekStartDay } from "./types";
|
|
|
20
21
|
* - `"snap-shrink"` — Snap to the boundary, then **shrink** the window to just
|
|
21
22
|
* the in-range weeks.
|
|
22
23
|
*
|
|
24
|
+
* A single bound (`min` only or `max` only) is honored; the missing side is unlimited.
|
|
25
|
+
*
|
|
23
26
|
* `"snap"` and `"snap-shrink"` are identical **unless the selectable range spans
|
|
24
27
|
* fewer weeks than `weekCount`** — i.e. the window is taller than the range.
|
|
25
28
|
* Snapping can only pin *one* edge to a bound; if the range is narrower than the
|
|
@@ -63,19 +66,33 @@ export type MonthOutOfRangeBehavior = "unbounded" | "stop";
|
|
|
63
66
|
/** Returns true if any day in the 7-day span starting at weekStart falls within [min, max]. */
|
|
64
67
|
function weekHasValidDay(
|
|
65
68
|
weekStart: Temporal.PlainDate,
|
|
66
|
-
min: Temporal.PlainDate,
|
|
67
|
-
max: Temporal.PlainDate,
|
|
69
|
+
min: Temporal.PlainDate | undefined,
|
|
70
|
+
max: Temporal.PlainDate | undefined,
|
|
68
71
|
T: TemporalNamespace,
|
|
69
72
|
): boolean {
|
|
70
73
|
// Week spans [weekStart, weekStart+6]. Overlaps with [min, max] iff
|
|
71
|
-
// weekStart <= max AND weekStart+6 >= min.
|
|
74
|
+
// weekStart <= max AND weekStart+6 >= min. A missing bound is unlimited.
|
|
72
75
|
const weekEnd = weekStart.add({ days: 6 });
|
|
73
76
|
return (
|
|
74
|
-
T.PlainDate.compare(weekStart, max) <= 0 &&
|
|
75
|
-
T.PlainDate.compare(weekEnd, min) >= 0
|
|
77
|
+
(!max || T.PlainDate.compare(weekStart, max) <= 0) &&
|
|
78
|
+
(!min || T.PlainDate.compare(weekEnd, min) >= 0)
|
|
76
79
|
);
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
/** Returns true if any of the `weekCount` weeks starting at firstWeek has a day in [min, max]. */
|
|
83
|
+
export function windowHasValidWeek(
|
|
84
|
+
firstWeek: Temporal.PlainDate,
|
|
85
|
+
weekCount: number,
|
|
86
|
+
min: Temporal.PlainDate | undefined,
|
|
87
|
+
max: Temporal.PlainDate | undefined,
|
|
88
|
+
T: TemporalNamespace,
|
|
89
|
+
): boolean {
|
|
90
|
+
for (let i = 0; i < weekCount; i++) {
|
|
91
|
+
if (weekHasValidDay(firstWeek.add({ weeks: i }), min, max, T)) return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
/**
|
|
80
97
|
* Returns the start of the week (per weekStartDay) that contains the given date.
|
|
81
98
|
* Uses dayOfWeek % 7 → Sun=0…Sat=6 convention.
|
|
@@ -83,31 +100,12 @@ function weekHasValidDay(
|
|
|
83
100
|
function weekStartContaining(
|
|
84
101
|
date: Temporal.PlainDate,
|
|
85
102
|
weekStartDay: WeekStartDay,
|
|
86
|
-
_T: TemporalNamespace,
|
|
87
103
|
): Temporal.PlainDate {
|
|
88
104
|
const dow = date.dayOfWeek % 7; // Sun=0…Sat=6
|
|
89
105
|
const daysFromStart = (dow - weekStartDay + 7) % 7;
|
|
90
106
|
return date.subtract({ days: daysFromStart });
|
|
91
107
|
}
|
|
92
108
|
|
|
93
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains min. */
|
|
94
|
-
function findFirstValidWeekStart(
|
|
95
|
-
min: Temporal.PlainDate,
|
|
96
|
-
weekStartDay: WeekStartDay,
|
|
97
|
-
T: TemporalNamespace,
|
|
98
|
-
): Temporal.PlainDate {
|
|
99
|
-
return weekStartContaining(min, weekStartDay, T);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Find the week start (per weekStartDay) whose 7-day span contains max. */
|
|
103
|
-
function findLastValidWeekStart(
|
|
104
|
-
max: Temporal.PlainDate,
|
|
105
|
-
weekStartDay: WeekStartDay,
|
|
106
|
-
T: TemporalNamespace,
|
|
107
|
-
): Temporal.PlainDate {
|
|
108
|
-
return weekStartContaining(max, weekStartDay, T);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
109
|
/**
|
|
112
110
|
* Trim leading and trailing fully-disabled weeks from a window.
|
|
113
111
|
* Returns new { firstWeek, weekCount }.
|
|
@@ -115,8 +113,8 @@ function findLastValidWeekStart(
|
|
|
115
113
|
function shrinkWindow(
|
|
116
114
|
firstWeek: Temporal.PlainDate,
|
|
117
115
|
weekCount: number,
|
|
118
|
-
min: Temporal.PlainDate,
|
|
119
|
-
max: Temporal.PlainDate,
|
|
116
|
+
min: Temporal.PlainDate | undefined,
|
|
117
|
+
max: Temporal.PlainDate | undefined,
|
|
120
118
|
T: TemporalNamespace,
|
|
121
119
|
): { firstWeek: Temporal.PlainDate; weekCount: number } {
|
|
122
120
|
let start = 0;
|
|
@@ -174,13 +172,14 @@ export function applyOutOfRange({
|
|
|
174
172
|
weekStartDay,
|
|
175
173
|
T,
|
|
176
174
|
}: ApplyOutOfRangeInput): { firstWeek: Temporal.PlainDate; weekCount: number } {
|
|
177
|
-
// Without bounds, all modes behave as unbounded
|
|
178
|
-
|
|
175
|
+
// Without bounds, all modes behave as unbounded. A single bound is honored;
|
|
176
|
+
// the missing side is unlimited.
|
|
177
|
+
if ((!min && !max) || behavior === "unbounded") {
|
|
179
178
|
return { firstWeek: targetFirstWeek, weekCount };
|
|
180
179
|
}
|
|
181
180
|
|
|
182
181
|
if (behavior === "stop") {
|
|
183
|
-
//
|
|
182
|
+
// Whether the move is allowed is decided by the caller (see WeekWindowPolicy)
|
|
184
183
|
return { firstWeek: targetFirstWeek, weekCount };
|
|
185
184
|
}
|
|
186
185
|
|
|
@@ -188,100 +187,25 @@ export function applyOutOfRange({
|
|
|
188
187
|
return shrinkWindow(targetFirstWeek, weekCount, min, max, T);
|
|
189
188
|
}
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (T.PlainDate.compare(targetLastWeek, lastValid) <= 0) {
|
|
207
|
-
// Target window fits within max — also check if it goes before min
|
|
208
|
-
const firstValid = findFirstValidWeekStart(min, weekStartDay, T);
|
|
209
|
-
if (T.PlainDate.compare(targetFirstWeek, firstValid) >= 0) {
|
|
210
|
-
resolvedFirst = targetFirstWeek;
|
|
211
|
-
} else {
|
|
212
|
-
// Overshoots min: snap forward so window starts at firstValid
|
|
213
|
-
resolvedFirst = firstValid;
|
|
214
|
-
}
|
|
215
|
-
} else {
|
|
216
|
-
// Overshoots max: snap back
|
|
217
|
-
resolvedFirst = snappedFirst;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (behavior === "snap-shrink") {
|
|
221
|
-
return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
222
|
-
}
|
|
223
|
-
return { firstWeek: resolvedFirst, weekCount };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return { firstWeek: targetFirstWeek, weekCount };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export interface CanShiftInput {
|
|
230
|
-
currentFirstWeek: Temporal.PlainDate;
|
|
231
|
-
weekCount: number;
|
|
232
|
-
direction: 1 | -1;
|
|
233
|
-
shiftBy?: number;
|
|
234
|
-
behavior: OutOfRangeBehavior;
|
|
235
|
-
min?: Temporal.PlainDate;
|
|
236
|
-
max?: Temporal.PlainDate;
|
|
237
|
-
weekStartDay: WeekStartDay;
|
|
238
|
-
T: TemporalNamespace;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Returns whether the navigation button for the given direction should be enabled.
|
|
243
|
-
*/
|
|
244
|
-
export function canShift({
|
|
245
|
-
currentFirstWeek,
|
|
246
|
-
weekCount,
|
|
247
|
-
direction,
|
|
248
|
-
shiftBy,
|
|
249
|
-
behavior,
|
|
250
|
-
min,
|
|
251
|
-
max,
|
|
252
|
-
weekStartDay,
|
|
253
|
-
T,
|
|
254
|
-
}: CanShiftInput): boolean {
|
|
255
|
-
if (behavior === "unbounded" || !min || !max) {
|
|
256
|
-
return true;
|
|
190
|
+
// snap | snap-shrink
|
|
191
|
+
const targetLastWeek = targetFirstWeek.add({ weeks: weekCount - 1 });
|
|
192
|
+
const lastValid = max && weekStartContaining(max, weekStartDay);
|
|
193
|
+
const firstValid = min && weekStartContaining(min, weekStartDay);
|
|
194
|
+
|
|
195
|
+
let resolvedFirst = targetFirstWeek;
|
|
196
|
+
if (lastValid && T.PlainDate.compare(targetLastWeek, lastValid) > 0) {
|
|
197
|
+
// Overshoots max: snap back so the window ends at the last in-range week
|
|
198
|
+
resolvedFirst = lastValid.subtract({ weeks: weekCount - 1 });
|
|
199
|
+
} else if (
|
|
200
|
+
firstValid &&
|
|
201
|
+
T.PlainDate.compare(targetFirstWeek, firstValid) < 0
|
|
202
|
+
) {
|
|
203
|
+
// Overshoots min: snap forward so the window starts at the first in-range week
|
|
204
|
+
resolvedFirst = firstValid;
|
|
257
205
|
}
|
|
258
206
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (behavior === "stop" || behavior === "stop-shrink") {
|
|
263
|
-
// Check if any week in the target window has valid days
|
|
264
|
-
for (let i = 0; i < weekCount; i++) {
|
|
265
|
-
const ws = targetFirstWeek.add({ days: i * 7 });
|
|
266
|
-
if (weekHasValidDay(ws, min, max, T)) return true;
|
|
267
|
-
}
|
|
268
|
-
return false;
|
|
207
|
+
if (behavior === "snap-shrink") {
|
|
208
|
+
return shrinkWindow(resolvedFirst, weekCount, min, max, T);
|
|
269
209
|
}
|
|
270
|
-
|
|
271
|
-
if (behavior === "snap" || behavior === "snap-shrink") {
|
|
272
|
-
// Disabled when the current position is already the snapped position
|
|
273
|
-
// (i.e. applying the out-of-range behavior to the target produces the same firstWeek)
|
|
274
|
-
const applied = applyOutOfRange({
|
|
275
|
-
targetFirstWeek,
|
|
276
|
-
weekCount,
|
|
277
|
-
behavior,
|
|
278
|
-
min,
|
|
279
|
-
max,
|
|
280
|
-
weekStartDay,
|
|
281
|
-
T,
|
|
282
|
-
});
|
|
283
|
-
return T.PlainDate.compare(applied.firstWeek, currentFirstWeek) !== 0;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return true;
|
|
210
|
+
return { firstWeek: resolvedFirst, weekCount };
|
|
287
211
|
}
|
package/src/today.test.tsx
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { render, screen, cleanup } from "@testing-library/react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
describe,
|
|
5
|
+
it,
|
|
6
|
+
expect,
|
|
7
|
+
vi,
|
|
8
|
+
afterEach,
|
|
9
|
+
beforeEach,
|
|
10
|
+
} from "vite-plus/test";
|
|
4
11
|
import {
|
|
5
12
|
Grid,
|
|
6
13
|
GridBody,
|
package/src/utils.bench.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import {
|
|
2
|
+
import { test, describe } from "vite-plus/test";
|
|
3
3
|
import type { TemporalNamespace } from "./types";
|
|
4
4
|
import {
|
|
5
5
|
getMonthWeeks,
|
|
@@ -29,82 +29,112 @@ const rangeEnd = Temporal.PlainDate.from("2026-03-20");
|
|
|
29
29
|
const midWeek = marchWeeks[2]!; // a week in the middle of the range
|
|
30
30
|
|
|
31
31
|
describe("getMonthWeeks", () => {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
test("generate month grid (March 2026)", async ({ bench }) => {
|
|
33
|
+
await bench("generate month grid (March 2026)", () => {
|
|
34
|
+
getMonthWeeks(2026, 3, T);
|
|
35
|
+
}).run();
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
test("generate month grid (February — short month)", async ({ bench }) => {
|
|
39
|
+
await bench("generate month grid (February — short month)", () => {
|
|
40
|
+
getMonthWeeks(2026, 2, T);
|
|
41
|
+
}).run();
|
|
38
42
|
});
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
test("generate month grid (August — 6-week grid)", async ({ bench }) => {
|
|
45
|
+
await bench("generate month grid (August — 6-week grid)", () => {
|
|
46
|
+
getMonthWeeks(2026, 8, T);
|
|
47
|
+
}).run();
|
|
42
48
|
});
|
|
43
49
|
});
|
|
44
50
|
|
|
45
51
|
describe("computeWeekRangeInfo", () => {
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
test("week fully inside range", async ({ bench }) => {
|
|
53
|
+
await bench("week fully inside range", () => {
|
|
54
|
+
computeWeekRangeInfo(midWeek, rangeStart, rangeEnd, T);
|
|
55
|
+
}).run();
|
|
48
56
|
});
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
test("week with no overlap", async ({ bench }) => {
|
|
59
|
+
await bench("week with no overlap", () => {
|
|
60
|
+
const noOverlapWeek = marchWeeks[marchWeeks.length - 1]!;
|
|
61
|
+
computeWeekRangeInfo(
|
|
62
|
+
noOverlapWeek,
|
|
63
|
+
Temporal.PlainDate.from("2026-03-01"),
|
|
64
|
+
Temporal.PlainDate.from("2026-03-04"),
|
|
65
|
+
T,
|
|
66
|
+
);
|
|
67
|
+
}).run();
|
|
58
68
|
});
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
test("no range (undefined bounds)", async ({ bench }) => {
|
|
71
|
+
await bench("no range (undefined bounds)", () => {
|
|
72
|
+
computeWeekRangeInfo(midWeek, undefined, undefined, T);
|
|
73
|
+
}).run();
|
|
62
74
|
});
|
|
63
75
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
test("all 6 weeks of a month", async ({ bench }) => {
|
|
77
|
+
await bench("all 6 weeks of a month", () => {
|
|
78
|
+
for (const week of marchWeeks) {
|
|
79
|
+
computeWeekRangeInfo(week, rangeStart, rangeEnd, T);
|
|
80
|
+
}
|
|
81
|
+
}).run();
|
|
68
82
|
});
|
|
69
83
|
});
|
|
70
84
|
|
|
71
85
|
describe("computeAdjacentMonth", () => {
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
test("next month", async ({ bench }) => {
|
|
87
|
+
await bench("next month", () => {
|
|
88
|
+
computeAdjacentMonth({ year: 2026, month: 3 }, "next", T);
|
|
89
|
+
}).run();
|
|
74
90
|
});
|
|
75
91
|
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
test("prev month", async ({ bench }) => {
|
|
93
|
+
await bench("prev month", () => {
|
|
94
|
+
computeAdjacentMonth({ year: 2026, month: 3 }, "prev", T);
|
|
95
|
+
}).run();
|
|
78
96
|
});
|
|
79
97
|
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
test("year boundary (Dec → Jan)", async ({ bench }) => {
|
|
99
|
+
await bench("year boundary (Dec → Jan)", () => {
|
|
100
|
+
computeAdjacentMonth({ year: 2026, month: 12 }, "next", T);
|
|
101
|
+
}).run();
|
|
82
102
|
});
|
|
83
103
|
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
test("year boundary (Jan → Dec)", async ({ bench }) => {
|
|
105
|
+
await bench("year boundary (Jan → Dec)", () => {
|
|
106
|
+
computeAdjacentMonth({ year: 2026, month: 1 }, "prev", T);
|
|
107
|
+
}).run();
|
|
86
108
|
});
|
|
87
109
|
});
|
|
88
110
|
|
|
89
111
|
describe("isInRange", () => {
|
|
90
112
|
const allDays = marchWeeks.flat();
|
|
91
113
|
|
|
92
|
-
|
|
93
|
-
|
|
114
|
+
test("single date check (in range)", async ({ bench }) => {
|
|
115
|
+
await bench("single date check (in range)", () => {
|
|
116
|
+
isInRange(Temporal.PlainDate.from("2026-03-10"), rangeStart, rangeEnd, T);
|
|
117
|
+
}).run();
|
|
94
118
|
});
|
|
95
119
|
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
test("single date check (out of range)", async ({ bench }) => {
|
|
121
|
+
await bench("single date check (out of range)", () => {
|
|
122
|
+
isInRange(Temporal.PlainDate.from("2026-03-25"), rangeStart, rangeEnd, T);
|
|
123
|
+
}).run();
|
|
98
124
|
});
|
|
99
125
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
126
|
+
test("check all 42 grid cells", async ({ bench }) => {
|
|
127
|
+
await bench("check all 42 grid cells", () => {
|
|
128
|
+
for (const day of allDays) {
|
|
129
|
+
isInRange(day, rangeStart, rangeEnd, T);
|
|
130
|
+
}
|
|
131
|
+
}).run();
|
|
104
132
|
});
|
|
105
133
|
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
test("undefined range (early exit)", async ({ bench }) => {
|
|
135
|
+
await bench("undefined range (early exit)", () => {
|
|
136
|
+
isInRange(Temporal.PlainDate.from("2026-03-10"), undefined, undefined, T);
|
|
137
|
+
}).run();
|
|
108
138
|
});
|
|
109
139
|
});
|
|
110
140
|
|
|
@@ -113,49 +143,65 @@ describe("toZonedDateTime / fromZonedDateTime", () => {
|
|
|
113
143
|
const plainDateTime = Temporal.PlainDateTime.from("2026-03-15T10:30:00");
|
|
114
144
|
const nativeDate = new Date(2026, 2, 15, 10, 30, 0);
|
|
115
145
|
|
|
116
|
-
|
|
117
|
-
|
|
146
|
+
test("PlainDate → ZonedDateTime", async ({ bench }) => {
|
|
147
|
+
await bench("PlainDate → ZonedDateTime", () => {
|
|
148
|
+
toZonedDateTime({ format: "PlainDate", value: plainDate }, timeZone, T);
|
|
149
|
+
}).run();
|
|
118
150
|
});
|
|
119
151
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
152
|
+
test("PlainDateTime → ZonedDateTime", async ({ bench }) => {
|
|
153
|
+
await bench("PlainDateTime → ZonedDateTime", () => {
|
|
154
|
+
toZonedDateTime(
|
|
155
|
+
{ format: "PlainDateTime", value: plainDateTime },
|
|
156
|
+
timeZone,
|
|
157
|
+
T,
|
|
158
|
+
);
|
|
159
|
+
}).run();
|
|
126
160
|
});
|
|
127
161
|
|
|
128
|
-
|
|
129
|
-
|
|
162
|
+
test("Date → ZonedDateTime", async ({ bench }) => {
|
|
163
|
+
await bench("Date → ZonedDateTime", () => {
|
|
164
|
+
toZonedDateTime({ format: "Date", value: nativeDate }, timeZone, T);
|
|
165
|
+
}).run();
|
|
130
166
|
});
|
|
131
167
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
168
|
+
test("ZonedDateTime → PlainDate", async ({ bench }) => {
|
|
169
|
+
await bench("ZonedDateTime → PlainDate", () => {
|
|
170
|
+
const zdt = plainDate.toZonedDateTime(timeZone);
|
|
171
|
+
fromZonedDateTime(zdt, "PlainDate", T);
|
|
172
|
+
}).run();
|
|
135
173
|
});
|
|
136
174
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
175
|
+
test("ZonedDateTime → object", async ({ bench }) => {
|
|
176
|
+
await bench("ZonedDateTime → object", () => {
|
|
177
|
+
const zdt = plainDate.toZonedDateTime(timeZone);
|
|
178
|
+
fromZonedDateTime(zdt, "object", T);
|
|
179
|
+
}).run();
|
|
140
180
|
});
|
|
141
181
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
182
|
+
test("round-trip PlainDate → ZDT → PlainDate", async ({ bench }) => {
|
|
183
|
+
await bench("round-trip PlainDate → ZDT → PlainDate", () => {
|
|
184
|
+
const zdt = toZonedDateTime(
|
|
185
|
+
{ format: "PlainDate", value: plainDate },
|
|
186
|
+
timeZone,
|
|
187
|
+
T,
|
|
188
|
+
);
|
|
189
|
+
fromZonedDateTime(zdt, "PlainDate", T);
|
|
190
|
+
}).run();
|
|
149
191
|
});
|
|
150
192
|
});
|
|
151
193
|
|
|
152
194
|
describe("getWeekdayNames", () => {
|
|
153
|
-
|
|
154
|
-
|
|
195
|
+
test("en-US locale (7× toLocaleString)", async ({ bench }) => {
|
|
196
|
+
await bench("en-US locale (7× toLocaleString)", () => {
|
|
197
|
+
getWeekdayNames("en-US", T);
|
|
198
|
+
}).run();
|
|
155
199
|
});
|
|
156
200
|
|
|
157
|
-
|
|
158
|
-
|
|
201
|
+
test("de-DE locale", async ({ bench }) => {
|
|
202
|
+
await bench("de-DE locale", () => {
|
|
203
|
+
getWeekdayNames("de-DE", T);
|
|
204
|
+
}).run();
|
|
159
205
|
});
|
|
160
206
|
});
|
|
161
207
|
|
|
@@ -165,43 +211,49 @@ describe("resolveFocusTarget", () => {
|
|
|
165
211
|
const currentMonth = { year: 2026, month: 3 };
|
|
166
212
|
const noDisabled = () => false;
|
|
167
213
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
214
|
+
test("focused date in grid (fast path)", async ({ bench }) => {
|
|
215
|
+
await bench("focused date in grid (fast path)", () => {
|
|
216
|
+
resolveFocusTarget(
|
|
217
|
+
focusedDate,
|
|
218
|
+
selectedDate,
|
|
219
|
+
marchWeeks,
|
|
220
|
+
currentMonth,
|
|
221
|
+
noDisabled,
|
|
222
|
+
T,
|
|
223
|
+
true,
|
|
224
|
+
);
|
|
225
|
+
}).run();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("selected date fallback", async ({ bench }) => {
|
|
229
|
+
await bench("selected date fallback", () => {
|
|
230
|
+
// Focus a date outside the grid to force fallback to selectedDate
|
|
231
|
+
const outsideFocus = Temporal.PlainDate.from("2026-05-01");
|
|
232
|
+
resolveFocusTarget(
|
|
233
|
+
outsideFocus,
|
|
234
|
+
selectedDate,
|
|
235
|
+
marchWeeks,
|
|
236
|
+
currentMonth,
|
|
237
|
+
noDisabled,
|
|
238
|
+
T,
|
|
239
|
+
true,
|
|
240
|
+
);
|
|
241
|
+
}).run();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("no match — linear scan to first enabled", async ({ bench }) => {
|
|
245
|
+
await bench("no match — linear scan to first enabled", () => {
|
|
246
|
+
const outsideFocus = Temporal.PlainDate.from("2026-05-01");
|
|
247
|
+
const outsideSelected = Temporal.PlainDate.from("2026-05-15");
|
|
248
|
+
resolveFocusTarget(
|
|
249
|
+
outsideFocus,
|
|
250
|
+
outsideSelected,
|
|
251
|
+
marchWeeks,
|
|
252
|
+
currentMonth,
|
|
253
|
+
noDisabled,
|
|
254
|
+
T,
|
|
255
|
+
true,
|
|
256
|
+
);
|
|
257
|
+
}).run();
|
|
206
258
|
});
|
|
207
259
|
});
|
package/src/utils.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
-
import { describe, it, expect } from "
|
|
2
|
+
import { describe, it, expect } from "vite-plus/test";
|
|
3
3
|
import { temporalVariants } from "./test-temporal";
|
|
4
4
|
import type { TemporalNamespace } from "./types";
|
|
5
5
|
import {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Temporal } from "@js-temporal/polyfill";
|
|
3
3
|
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
|
-
import { describe, expect, it } from "
|
|
5
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
6
6
|
import {
|
|
7
7
|
DayButton,
|
|
8
8
|
DayCellTemplate,
|