@klinking/colander 0.0.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/formats/date.cjs +49 -0
- package/dist/formats/date.d.cts +45 -0
- package/dist/formats/date.d.mts +45 -0
- package/dist/formats/date.mjs +2 -0
- package/dist/formats/object.cjs +49 -0
- package/dist/formats/object.d.cts +45 -0
- package/dist/formats/object.d.mts +45 -0
- package/dist/formats/object.mjs +2 -0
- package/dist/formats/plain-date-time.cjs +49 -0
- package/dist/formats/plain-date-time.d.cts +45 -0
- package/dist/formats/plain-date-time.d.mts +45 -0
- package/dist/formats/plain-date-time.mjs +2 -0
- package/dist/formats/plain-date.cjs +49 -0
- package/dist/formats/plain-date.d.cts +45 -0
- package/dist/formats/plain-date.d.mts +45 -0
- package/dist/formats/plain-date.mjs +2 -0
- package/dist/formats/plain-month-day.cjs +49 -0
- package/dist/formats/plain-month-day.d.cts +45 -0
- package/dist/formats/plain-month-day.d.mts +45 -0
- package/dist/formats/plain-month-day.mjs +2 -0
- package/dist/formats/plain-year-month.cjs +49 -0
- package/dist/formats/plain-year-month.d.cts +45 -0
- package/dist/formats/plain-year-month.d.mts +45 -0
- package/dist/formats/plain-year-month.mjs +2 -0
- package/dist/formats/zoned-date-time.cjs +49 -0
- package/dist/formats/zoned-date-time.d.cts +45 -0
- package/dist/formats/zoned-date-time.d.mts +45 -0
- package/dist/formats/zoned-date-time.mjs +2 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
- package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
- package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
- package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
- package/package.json +89 -0
- package/src/calendar-context.ts +22 -0
- package/src/calendar-provider.test.tsx +123 -0
- package/src/calendar-provider.tsx +538 -0
- package/src/calendar-types.ts +212 -0
- package/src/compute-weeks-in-window.test.ts +83 -0
- package/src/compute-weeks-in-window.ts +40 -0
- package/src/context.ts +34 -0
- package/src/day-cell.tsx +635 -0
- package/src/drag-handle.tsx +137 -0
- package/src/formats/date.ts +110 -0
- package/src/formats/formats.test.ts +18 -0
- package/src/formats/object.ts +110 -0
- package/src/formats/plain-date-time.ts +110 -0
- package/src/formats/plain-date.ts +110 -0
- package/src/formats/plain-month-day.ts +110 -0
- package/src/formats/plain-year-month.ts +110 -0
- package/src/formats/zoned-date-time.ts +110 -0
- package/src/grid-header.tsx +141 -0
- package/src/grid.event-perf.test.tsx +282 -0
- package/src/grid.perf.test.tsx +467 -0
- package/src/grid.tsx +608 -0
- package/src/index.ts +116 -0
- package/src/keyboard.test.ts +498 -0
- package/src/keyboard.ts +142 -0
- package/src/month-separator.test.tsx +183 -0
- package/src/month-separator.tsx +238 -0
- package/src/month-view-context.ts +26 -0
- package/src/month-view-types.ts +89 -0
- package/src/month-view.test.tsx +1433 -0
- package/src/month-view.tsx +373 -0
- package/src/navigation.tsx +350 -0
- package/src/overflow.test.ts +124 -0
- package/src/overflow.ts +233 -0
- package/src/range-preview.tsx +90 -0
- package/src/resolve-first-week.test.ts +132 -0
- package/src/resolve-first-week.ts +145 -0
- package/src/root-selection.ts +621 -0
- package/src/selected-range.tsx +163 -0
- package/src/temporal-polyfill.test.ts +317 -0
- package/src/temporal-polyfill.ts +566 -0
- package/src/test-temporal.ts +17 -0
- package/src/types.ts +814 -0
- package/src/utils.bench.ts +183 -0
- package/src/utils.test.ts +983 -0
- package/src/utils.ts +493 -0
- package/src/view-context.ts +28 -0
- package/src/week-number.tsx +118 -0
- package/src/weeks-grid.tsx +265 -0
- package/src/weeks-keyboard.test.ts +222 -0
- package/src/weeks-keyboard.ts +156 -0
- package/src/weeks-navigation.tsx +209 -0
- package/src/weeks-view-context.ts +26 -0
- package/src/weeks-view-state.ts +421 -0
- package/src/weeks-view-types.ts +102 -0
- package/src/weeks-view.test.tsx +479 -0
- package/src/weeks-view.tsx +127 -0
|
@@ -0,0 +1,983 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { temporalVariants } from "./test-temporal";
|
|
4
|
+
import type { TemporalNamespace } from "./types";
|
|
5
|
+
import {
|
|
6
|
+
calendarForLocale,
|
|
7
|
+
resolveTemporal,
|
|
8
|
+
getSystemTimeZone,
|
|
9
|
+
toZonedDateTime,
|
|
10
|
+
fromZonedDateTime,
|
|
11
|
+
selectedToZdt,
|
|
12
|
+
getMonthWeeks,
|
|
13
|
+
zdtToNativeDate,
|
|
14
|
+
sameCalendarDay,
|
|
15
|
+
getReferenceWeekStart,
|
|
16
|
+
computeAdjacentMonth,
|
|
17
|
+
focusedDateForMonth,
|
|
18
|
+
resolveFocusTarget,
|
|
19
|
+
shouldMoveDomFocus,
|
|
20
|
+
isInRange,
|
|
21
|
+
computeWeekRangeInfo,
|
|
22
|
+
getWeekdayNames,
|
|
23
|
+
getISOWeekNumber,
|
|
24
|
+
} from "./utils";
|
|
25
|
+
|
|
26
|
+
const T: TemporalNamespace = {
|
|
27
|
+
Now: Temporal.Now,
|
|
28
|
+
PlainDate: Temporal.PlainDate,
|
|
29
|
+
PlainDateTime: Temporal.PlainDateTime,
|
|
30
|
+
PlainMonthDay: Temporal.PlainMonthDay,
|
|
31
|
+
PlainYearMonth: Temporal.PlainYearMonth,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("calendarForLocale", () => {
|
|
35
|
+
it("returns 'gregory' for en-US", () => {
|
|
36
|
+
expect(calendarForLocale("en-US")).toBe("gregory");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns a calendar string for an empty locale (runtime default)", () => {
|
|
40
|
+
const result = calendarForLocale("");
|
|
41
|
+
expect(typeof result).toBe("string");
|
|
42
|
+
expect(result.length).toBeGreaterThan(0);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("resolveTemporal", () => {
|
|
47
|
+
it("returns the provided namespace when given", () => {
|
|
48
|
+
expect(resolveTemporal(T)).toBe(T);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("throws when no namespace is provided and globalThis.Temporal is absent", () => {
|
|
52
|
+
const orig = (globalThis as any).Temporal;
|
|
53
|
+
delete (globalThis as any).Temporal;
|
|
54
|
+
try {
|
|
55
|
+
expect(() => resolveTemporal()).toThrow("Temporal is not available");
|
|
56
|
+
} finally {
|
|
57
|
+
if (orig) (globalThis as any).Temporal = orig;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe.each(temporalVariants)("getSystemTimeZone ($name)", ({ T }) => {
|
|
63
|
+
it("returns a non-empty IANA time zone string", () => {
|
|
64
|
+
const tz = getSystemTimeZone(T);
|
|
65
|
+
expect(typeof tz).toBe("string");
|
|
66
|
+
expect(tz.length).toBeGreaterThan(0);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("toZonedDateTime", () => {
|
|
71
|
+
const tz = "America/New_York";
|
|
72
|
+
|
|
73
|
+
it("converts PlainDate to ZonedDateTime", () => {
|
|
74
|
+
const pd = Temporal.PlainDate.from("2026-03-15");
|
|
75
|
+
const zdt = toZonedDateTime({ format: "PlainDate", value: pd }, tz, T);
|
|
76
|
+
expect(zdt.year).toBe(2026);
|
|
77
|
+
expect(zdt.month).toBe(3);
|
|
78
|
+
expect(zdt.day).toBe(15);
|
|
79
|
+
expect(zdt.timeZoneId).toBe(tz);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("converts PlainDateTime to ZonedDateTime", () => {
|
|
83
|
+
const pdt = Temporal.PlainDateTime.from("2026-03-15T10:30:00");
|
|
84
|
+
const zdt = toZonedDateTime({ format: "PlainDateTime", value: pdt }, tz, T);
|
|
85
|
+
expect(zdt.year).toBe(2026);
|
|
86
|
+
expect(zdt.hour).toBe(10);
|
|
87
|
+
expect(zdt.minute).toBe(30);
|
|
88
|
+
expect(zdt.timeZoneId).toBe(tz);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("converts PlainMonthDay to ZonedDateTime (uses current year)", () => {
|
|
92
|
+
const pmd = Temporal.PlainMonthDay.from({ month: 7, day: 4 });
|
|
93
|
+
const zdt = toZonedDateTime({ format: "PlainMonthDay", value: pmd }, tz, T);
|
|
94
|
+
expect(zdt.month).toBe(7);
|
|
95
|
+
expect(zdt.day).toBe(4);
|
|
96
|
+
expect(zdt.timeZoneId).toBe(tz);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("converts PlainTime to ZonedDateTime (uses current date)", () => {
|
|
100
|
+
const pt = Temporal.PlainTime.from("14:30:00");
|
|
101
|
+
const zdt = toZonedDateTime({ format: "PlainTime", value: pt }, tz, T);
|
|
102
|
+
expect(zdt.hour).toBe(14);
|
|
103
|
+
expect(zdt.minute).toBe(30);
|
|
104
|
+
expect(zdt.timeZoneId).toBe(tz);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("converts PlainYearMonth to ZonedDateTime (day 1)", () => {
|
|
108
|
+
const pym = Temporal.PlainYearMonth.from({ year: 2026, month: 6 });
|
|
109
|
+
const zdt = toZonedDateTime({ format: "PlainYearMonth", value: pym }, tz, T);
|
|
110
|
+
expect(zdt.year).toBe(2026);
|
|
111
|
+
expect(zdt.month).toBe(6);
|
|
112
|
+
expect(zdt.day).toBe(1);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("passes through ZonedDateTime unchanged", () => {
|
|
116
|
+
const orig = Temporal.PlainDate.from("2026-03-15").toZonedDateTime(tz);
|
|
117
|
+
const zdt = toZonedDateTime({ format: "ZonedDateTime", value: orig }, tz, T);
|
|
118
|
+
expect(Temporal.ZonedDateTime.compare(zdt, orig)).toBe(0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("converts a plain object to ZonedDateTime", () => {
|
|
122
|
+
const obj = { year: 2026, month: 3, day: 15, hour: 10, minute: 0 };
|
|
123
|
+
const zdt = toZonedDateTime({ format: "object", value: obj }, tz, T);
|
|
124
|
+
expect(zdt.year).toBe(2026);
|
|
125
|
+
expect(zdt.month).toBe(3);
|
|
126
|
+
expect(zdt.day).toBe(15);
|
|
127
|
+
expect(zdt.hour).toBe(10);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("converts a plain object with partial fields (fills defaults)", () => {
|
|
131
|
+
const zdt = toZonedDateTime({ format: "object", value: {} }, tz, T);
|
|
132
|
+
expect(zdt.timeZoneId).toBe(tz);
|
|
133
|
+
expect(zdt.year).toBeGreaterThan(2000);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("converts a plain object with custom timeZone", () => {
|
|
137
|
+
const obj = {
|
|
138
|
+
year: 2026,
|
|
139
|
+
month: 1,
|
|
140
|
+
day: 1,
|
|
141
|
+
timeZone: "Europe/London",
|
|
142
|
+
};
|
|
143
|
+
const zdt = toZonedDateTime({ format: "object", value: obj }, tz, T);
|
|
144
|
+
expect(zdt.timeZoneId).toBe("Europe/London");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("converts a native Date to ZonedDateTime", () => {
|
|
148
|
+
const nativeDate = new Date(2026, 2, 15, 10, 30, 0);
|
|
149
|
+
const zdt = toZonedDateTime({ format: "Date", value: nativeDate }, tz, T);
|
|
150
|
+
expect(zdt.year).toBe(2026);
|
|
151
|
+
expect(zdt.month).toBe(3);
|
|
152
|
+
expect(zdt.day).toBe(15);
|
|
153
|
+
expect(zdt.hour).toBe(10);
|
|
154
|
+
expect(zdt.minute).toBe(30);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("fromZonedDateTime", () => {
|
|
159
|
+
const tz = "America/New_York";
|
|
160
|
+
const zdt = Temporal.PlainDateTime.from("2026-03-15T10:30:45").toZonedDateTime(tz);
|
|
161
|
+
|
|
162
|
+
it("extracts PlainDate", () => {
|
|
163
|
+
const result = fromZonedDateTime(zdt, "PlainDate", T);
|
|
164
|
+
expect(result.format).toBe("PlainDate");
|
|
165
|
+
expect((result.value as Temporal.PlainDate).toString()).toBe("2026-03-15");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("extracts PlainDateTime", () => {
|
|
169
|
+
const result = fromZonedDateTime(zdt, "PlainDateTime", T);
|
|
170
|
+
expect(result.format).toBe("PlainDateTime");
|
|
171
|
+
expect((result.value as Temporal.PlainDateTime).hour).toBe(10);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("extracts PlainMonthDay", () => {
|
|
175
|
+
const result = fromZonedDateTime(zdt, "PlainMonthDay", T);
|
|
176
|
+
expect(result.format).toBe("PlainMonthDay");
|
|
177
|
+
const pmd = result.value as Temporal.PlainMonthDay;
|
|
178
|
+
expect(pmd.monthCode).toBe("M03");
|
|
179
|
+
expect(pmd.day).toBe(15);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("extracts PlainTime", () => {
|
|
183
|
+
const result = fromZonedDateTime(zdt, "PlainTime", T);
|
|
184
|
+
expect(result.format).toBe("PlainTime");
|
|
185
|
+
const pt = result.value as Temporal.PlainTime;
|
|
186
|
+
expect(pt.hour).toBe(10);
|
|
187
|
+
expect(pt.minute).toBe(30);
|
|
188
|
+
expect(pt.second).toBe(45);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("extracts PlainYearMonth", () => {
|
|
192
|
+
const result = fromZonedDateTime(zdt, "PlainYearMonth", T);
|
|
193
|
+
expect(result.format).toBe("PlainYearMonth");
|
|
194
|
+
const pym = result.value as Temporal.PlainYearMonth;
|
|
195
|
+
expect(pym.year).toBe(2026);
|
|
196
|
+
expect(pym.month).toBe(3);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("passes through ZonedDateTime", () => {
|
|
200
|
+
const result = fromZonedDateTime(zdt, "ZonedDateTime", T);
|
|
201
|
+
expect(result.format).toBe("ZonedDateTime");
|
|
202
|
+
expect(Temporal.ZonedDateTime.compare(result.value as any, zdt)).toBe(0);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("extracts a plain object with all fields", () => {
|
|
206
|
+
const result = fromZonedDateTime(zdt, "object", T);
|
|
207
|
+
expect(result.format).toBe("object");
|
|
208
|
+
const obj = result.value as any;
|
|
209
|
+
expect(obj.year).toBe(2026);
|
|
210
|
+
expect(obj.month).toBe(3);
|
|
211
|
+
expect(obj.day).toBe(15);
|
|
212
|
+
expect(obj.hour).toBe(10);
|
|
213
|
+
expect(obj.minute).toBe(30);
|
|
214
|
+
expect(obj.second).toBe(45);
|
|
215
|
+
expect(obj.timeZone).toBe(tz);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("extracts a native Date", () => {
|
|
219
|
+
const result = fromZonedDateTime(zdt, "Date", T);
|
|
220
|
+
expect(result.format).toBe("Date");
|
|
221
|
+
expect(result.value).toBeInstanceOf(Date);
|
|
222
|
+
expect((result.value as Date).getFullYear()).toBe(2026);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("round-trips: toZonedDateTime → fromZonedDateTime preserves PlainDate", () => {
|
|
226
|
+
const pd = Temporal.PlainDate.from("2026-06-20");
|
|
227
|
+
const intermediate = toZonedDateTime({ format: "PlainDate", value: pd }, tz, T);
|
|
228
|
+
const result = fromZonedDateTime(intermediate, "PlainDate", T);
|
|
229
|
+
expect((result.value as Temporal.PlainDate).toString()).toBe("2026-06-20");
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("selectedToZdt", () => {
|
|
234
|
+
const tz = "UTC";
|
|
235
|
+
|
|
236
|
+
it("returns undefined when selected is undefined", () => {
|
|
237
|
+
expect(selectedToZdt(undefined, tz, T)).toBeUndefined();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("converts a DateValueObject to ZonedDateTime", () => {
|
|
241
|
+
const pd = Temporal.PlainDate.from("2026-03-15");
|
|
242
|
+
const result = selectedToZdt({ format: "PlainDate", value: pd }, tz, T);
|
|
243
|
+
expect(result).toBeDefined();
|
|
244
|
+
expect(result!.year).toBe(2026);
|
|
245
|
+
expect(result!.month).toBe(3);
|
|
246
|
+
expect(result!.day).toBe(15);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("zdtToNativeDate", () => {
|
|
251
|
+
it("converts a ZonedDateTime to a native Date with the correct epoch", () => {
|
|
252
|
+
const zdt = Temporal.PlainDateTime.from("2026-01-01T00:00:00").toZonedDateTime("UTC");
|
|
253
|
+
const native = zdtToNativeDate(zdt);
|
|
254
|
+
expect(native).toBeInstanceOf(Date);
|
|
255
|
+
expect(native.toISOString()).toBe("2026-01-01T00:00:00.000Z");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("preserves millisecond precision", () => {
|
|
259
|
+
const zdt = Temporal.PlainDateTime.from("2026-06-15T12:30:00").toZonedDateTime("UTC");
|
|
260
|
+
const native = zdtToNativeDate(zdt);
|
|
261
|
+
expect(native.getUTCHours()).toBe(12);
|
|
262
|
+
expect(native.getUTCMinutes()).toBe(30);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe("sameCalendarDay", () => {
|
|
267
|
+
it("returns true when year, month, and day match", () => {
|
|
268
|
+
const zdt = Temporal.PlainDateTime.from("2026-03-15T10:00:00").toZonedDateTime("UTC");
|
|
269
|
+
const pd = Temporal.PlainDate.from("2026-03-15");
|
|
270
|
+
expect(sameCalendarDay(zdt, pd)).toBe(true);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("returns true even when times differ", () => {
|
|
274
|
+
const zdt = Temporal.PlainDateTime.from("2026-03-15T23:59:59").toZonedDateTime("UTC");
|
|
275
|
+
const pd = Temporal.PlainDate.from("2026-03-15");
|
|
276
|
+
expect(sameCalendarDay(zdt, pd)).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("returns false when days differ", () => {
|
|
280
|
+
const zdt = Temporal.PlainDateTime.from("2026-03-15T10:00:00").toZonedDateTime("UTC");
|
|
281
|
+
const pd = Temporal.PlainDate.from("2026-03-16");
|
|
282
|
+
expect(sameCalendarDay(zdt, pd)).toBe(false);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("returns false when months differ", () => {
|
|
286
|
+
const zdt = Temporal.PlainDateTime.from("2026-03-15T10:00:00").toZonedDateTime("UTC");
|
|
287
|
+
const pd = Temporal.PlainDate.from("2026-04-15");
|
|
288
|
+
expect(sameCalendarDay(zdt, pd)).toBe(false);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("returns false when years differ", () => {
|
|
292
|
+
const zdt = Temporal.PlainDateTime.from("2026-03-15T10:00:00").toZonedDateTime("UTC");
|
|
293
|
+
const pd = Temporal.PlainDate.from("2027-03-15");
|
|
294
|
+
expect(sameCalendarDay(zdt, pd)).toBe(false);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe.each(temporalVariants)("getReferenceWeekStart ($name)", ({ T }) => {
|
|
299
|
+
it("returns 2024-01-07 (Sunday) with default weekStartDay", () => {
|
|
300
|
+
expect(getReferenceWeekStart(T).toString()).toBe("2024-01-07");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("default is actually a Sunday (ISO dayOfWeek 7)", () => {
|
|
304
|
+
expect(getReferenceWeekStart(T).dayOfWeek).toBe(7);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("returns Monday when weekStartDay=1", () => {
|
|
308
|
+
const ref = getReferenceWeekStart(T, 1);
|
|
309
|
+
expect(ref.dayOfWeek).toBe(1);
|
|
310
|
+
expect(ref.toString()).toBe("2024-01-08");
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("returns Saturday when weekStartDay=6", () => {
|
|
314
|
+
const ref = getReferenceWeekStart(T, 6);
|
|
315
|
+
expect(ref.dayOfWeek).toBe(6);
|
|
316
|
+
expect(ref.toString()).toBe("2024-01-13");
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe.each(temporalVariants)("getWeekdayNames ($name)", ({ T }) => {
|
|
321
|
+
it("returns exactly 7 entries", () => {
|
|
322
|
+
expect(getWeekdayNames("en-US", T)).toHaveLength(7);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("starts with Sunday for en-US", () => {
|
|
326
|
+
const names = getWeekdayNames("en-US", T);
|
|
327
|
+
expect(names[0].long).toBe("Sunday");
|
|
328
|
+
expect(names[0].short).toBe("Sun");
|
|
329
|
+
expect(names[0].narrow).toBe("S");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("ends with Saturday for en-US", () => {
|
|
333
|
+
const names = getWeekdayNames("en-US", T);
|
|
334
|
+
expect(names[6].long).toBe("Saturday");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("contains all 7 unique long names", () => {
|
|
338
|
+
const names = getWeekdayNames("en-US", T);
|
|
339
|
+
const longs = names.map((n) => n.long);
|
|
340
|
+
expect(new Set(longs).size).toBe(7);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("each entry has long, short, and narrow properties", () => {
|
|
344
|
+
const names = getWeekdayNames("en-US", T);
|
|
345
|
+
for (const name of names) {
|
|
346
|
+
expect(typeof name.long).toBe("string");
|
|
347
|
+
expect(typeof name.short).toBe("string");
|
|
348
|
+
expect(typeof name.narrow).toBe("string");
|
|
349
|
+
expect(name.long.length).toBeGreaterThan(0);
|
|
350
|
+
expect(name.short.length).toBeGreaterThan(0);
|
|
351
|
+
expect(name.narrow.length).toBeGreaterThan(0);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("produces localized names for a non-English locale", () => {
|
|
356
|
+
const names = getWeekdayNames("de-DE", T);
|
|
357
|
+
expect(names[0].long).toBe("Sonntag");
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("starts with Monday when weekStartDay=1", () => {
|
|
361
|
+
const names = getWeekdayNames("en-US", T, 1);
|
|
362
|
+
expect(names[0].long).toBe("Monday");
|
|
363
|
+
expect(names[6].long).toBe("Sunday");
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("starts with Saturday when weekStartDay=6", () => {
|
|
367
|
+
const names = getWeekdayNames("en-US", T, 6);
|
|
368
|
+
expect(names[0].long).toBe("Saturday");
|
|
369
|
+
expect(names[1].long).toBe("Sunday");
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe.each(temporalVariants)("computeAdjacentMonth ($name)", ({ T }) => {
|
|
374
|
+
it.each<{
|
|
375
|
+
description: string;
|
|
376
|
+
current: { year: number; month: number };
|
|
377
|
+
direction: "prev" | "next";
|
|
378
|
+
expected: { year: number; month: number; firstDay: string };
|
|
379
|
+
}>([
|
|
380
|
+
{
|
|
381
|
+
description: "mid-year next",
|
|
382
|
+
current: { year: 2026, month: 3 },
|
|
383
|
+
direction: "next",
|
|
384
|
+
expected: { year: 2026, month: 4, firstDay: "2026-04-01" },
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
description: "mid-year prev",
|
|
388
|
+
current: { year: 2026, month: 3 },
|
|
389
|
+
direction: "prev",
|
|
390
|
+
expected: { year: 2026, month: 2, firstDay: "2026-02-01" },
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
description: "Dec→Jan wrap",
|
|
394
|
+
current: { year: 2026, month: 12 },
|
|
395
|
+
direction: "next",
|
|
396
|
+
expected: { year: 2027, month: 1, firstDay: "2027-01-01" },
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
description: "Jan→Dec wrap",
|
|
400
|
+
current: { year: 2027, month: 1 },
|
|
401
|
+
direction: "prev",
|
|
402
|
+
expected: { year: 2026, month: 12, firstDay: "2026-12-01" },
|
|
403
|
+
},
|
|
404
|
+
])("$description", ({ current, direction, expected }) => {
|
|
405
|
+
const result = computeAdjacentMonth(current, direction, T);
|
|
406
|
+
expect(result.year).toBe(expected.year);
|
|
407
|
+
expect(result.month).toBe(expected.month);
|
|
408
|
+
expect(result.firstDay.toString()).toBe(expected.firstDay);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
describe.each(temporalVariants)("focusedDateForMonth ($name)", ({ T }) => {
|
|
413
|
+
const d = (iso: string) => T.PlainDate.from(iso);
|
|
414
|
+
|
|
415
|
+
it.each<{
|
|
416
|
+
description: string;
|
|
417
|
+
focused: string;
|
|
418
|
+
targetMonth: { year: number; month: number };
|
|
419
|
+
firstDay: string;
|
|
420
|
+
expected: string;
|
|
421
|
+
}>([
|
|
422
|
+
{
|
|
423
|
+
description: "falls back to firstDay when in a different month",
|
|
424
|
+
focused: "2026-03-15",
|
|
425
|
+
targetMonth: { year: 2026, month: 4 },
|
|
426
|
+
firstDay: "2026-04-01",
|
|
427
|
+
expected: "2026-04-01",
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
description: "preserves focused when already in target month",
|
|
431
|
+
focused: "2026-04-10",
|
|
432
|
+
targetMonth: { year: 2026, month: 4 },
|
|
433
|
+
firstDay: "2026-04-01",
|
|
434
|
+
expected: "2026-04-10",
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
description: "falls back to firstDay when in a different year",
|
|
438
|
+
focused: "2025-12-20",
|
|
439
|
+
targetMonth: { year: 2026, month: 1 },
|
|
440
|
+
firstDay: "2026-01-01",
|
|
441
|
+
expected: "2026-01-01",
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
description: "preserves focused at month boundary (day 1)",
|
|
445
|
+
focused: "2026-05-01",
|
|
446
|
+
targetMonth: { year: 2026, month: 5 },
|
|
447
|
+
firstDay: "2026-05-01",
|
|
448
|
+
expected: "2026-05-01",
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
description: "preserves focused at month boundary (last day)",
|
|
452
|
+
focused: "2026-05-31",
|
|
453
|
+
targetMonth: { year: 2026, month: 5 },
|
|
454
|
+
firstDay: "2026-05-01",
|
|
455
|
+
expected: "2026-05-31",
|
|
456
|
+
},
|
|
457
|
+
])("$description", ({ focused, targetMonth, firstDay, expected }) => {
|
|
458
|
+
const result = focusedDateForMonth(d(focused), targetMonth, d(firstDay));
|
|
459
|
+
expect(result.toString()).toBe(expected);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
describe.each(temporalVariants)("getMonthWeeks ($name)", ({ T }) => {
|
|
464
|
+
const d = (iso: string) => T.PlainDate.from(iso);
|
|
465
|
+
|
|
466
|
+
it("returns weeks with 7 days each", () => {
|
|
467
|
+
const weeks = getMonthWeeks(2026, 3, T);
|
|
468
|
+
for (const week of weeks) {
|
|
469
|
+
expect(week).toHaveLength(7);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it("returns between 4 and 6 weeks for any month", () => {
|
|
474
|
+
for (let month = 1; month <= 12; month++) {
|
|
475
|
+
const weeks = getMonthWeeks(2026, month, T);
|
|
476
|
+
expect(weeks.length).toBeGreaterThanOrEqual(4);
|
|
477
|
+
expect(weeks.length).toBeLessThanOrEqual(6);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("starts each week on Sunday (dayOfWeek === 7 in ISO)", () => {
|
|
482
|
+
const weeks = getMonthWeeks(2026, 3, T);
|
|
483
|
+
for (const week of weeks) {
|
|
484
|
+
expect(week[0].dayOfWeek).toBe(7);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("ends each week on Saturday (dayOfWeek === 6 in ISO)", () => {
|
|
489
|
+
const weeks = getMonthWeeks(2026, 3, T);
|
|
490
|
+
for (const week of weeks) {
|
|
491
|
+
expect(week[6].dayOfWeek).toBe(6);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it("includes the first and last day of the month", () => {
|
|
496
|
+
const weeks = getMonthWeeks(2026, 3, T);
|
|
497
|
+
const allDays = weeks.flat();
|
|
498
|
+
const hasFirst = allDays.some((dd) => dd.toString() === "2026-03-01");
|
|
499
|
+
const hasLast = allDays.some((dd) => dd.toString() === "2026-03-31");
|
|
500
|
+
expect(hasFirst).toBe(true);
|
|
501
|
+
expect(hasLast).toBe(true);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it("February 2026 has exactly 4 weeks (starts on Sunday)", () => {
|
|
505
|
+
const weeks = getMonthWeeks(2026, 2, T);
|
|
506
|
+
expect(weeks.length).toBe(4);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("Monday-start: starts each week on Monday (dayOfWeek === 1 in ISO)", () => {
|
|
510
|
+
const weeks = getMonthWeeks(2026, 3, T, { weekStartDay: 1 });
|
|
511
|
+
for (const week of weeks) {
|
|
512
|
+
expect(week[0].dayOfWeek).toBe(1);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it("Monday-start: ends each week on Sunday (dayOfWeek === 7 in ISO)", () => {
|
|
517
|
+
const weeks = getMonthWeeks(2026, 3, T, { weekStartDay: 1 });
|
|
518
|
+
for (const week of weeks) {
|
|
519
|
+
expect(week[6].dayOfWeek).toBe(7);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it("Saturday-start: starts each week on Saturday (dayOfWeek === 6 in ISO)", () => {
|
|
524
|
+
const weeks = getMonthWeeks(2026, 3, T, { weekStartDay: 6 });
|
|
525
|
+
for (const week of weeks) {
|
|
526
|
+
expect(week[0].dayOfWeek).toBe(6);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("Saturday-start: ends each week on Friday (dayOfWeek === 5 in ISO)", () => {
|
|
531
|
+
const weeks = getMonthWeeks(2026, 3, T, { weekStartDay: 6 });
|
|
532
|
+
for (const week of weeks) {
|
|
533
|
+
expect(week[6].dayOfWeek).toBe(5);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it("fixedWeeks: always returns 6 weeks", () => {
|
|
538
|
+
for (let month = 1; month <= 12; month++) {
|
|
539
|
+
const weeks = getMonthWeeks(2026, month, T, { fixedWeeks: true });
|
|
540
|
+
expect(weeks.length).toBe(6);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("fixedWeeks: February 2026 (4 weeks normally) returns 6 weeks", () => {
|
|
545
|
+
const weeks = getMonthWeeks(2026, 2, T, { fixedWeeks: true });
|
|
546
|
+
expect(weeks.length).toBe(6);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("fixedWeeks + Monday-start: always returns 6 weeks with Monday starts", () => {
|
|
550
|
+
for (let month = 1; month <= 12; month++) {
|
|
551
|
+
const weeks = getMonthWeeks(2026, month, T, {
|
|
552
|
+
weekStartDay: 1,
|
|
553
|
+
fixedWeeks: true,
|
|
554
|
+
});
|
|
555
|
+
expect(weeks.length).toBe(6);
|
|
556
|
+
for (const week of weeks) {
|
|
557
|
+
expect(week[0].dayOfWeek).toBe(1);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("month navigation + focus: simulates prev/next and verifies a focusable day exists", () => {
|
|
563
|
+
const current = { year: 2026, month: 3 };
|
|
564
|
+
const focusedDate = d("2026-03-15");
|
|
565
|
+
|
|
566
|
+
const next = computeAdjacentMonth(current, "next", T);
|
|
567
|
+
const newFocused = focusedDateForMonth(focusedDate, next, next.firstDay);
|
|
568
|
+
const nextWeeks = getMonthWeeks(next.year, next.month, T);
|
|
569
|
+
const allNextDays = nextWeeks.flat();
|
|
570
|
+
|
|
571
|
+
expect(allNextDays.some((dd) => T.PlainDate.compare(dd, newFocused) === 0)).toBe(true);
|
|
572
|
+
|
|
573
|
+
const prev = computeAdjacentMonth(current, "prev", T);
|
|
574
|
+
const prevFocused = focusedDateForMonth(focusedDate, prev, prev.firstDay);
|
|
575
|
+
const prevWeeks = getMonthWeeks(prev.year, prev.month, T);
|
|
576
|
+
const allPrevDays = prevWeeks.flat();
|
|
577
|
+
|
|
578
|
+
expect(allPrevDays.some((dd) => T.PlainDate.compare(dd, prevFocused) === 0)).toBe(true);
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
describe.each(temporalVariants)("resolveFocusTarget ($name)", ({ T }) => {
|
|
583
|
+
const d = (iso: string) => T.PlainDate.from(iso);
|
|
584
|
+
const noDisabled = () => false;
|
|
585
|
+
const marchWeeks = getMonthWeeks(2026, 3, T);
|
|
586
|
+
const march = { year: 2026, month: 3 };
|
|
587
|
+
|
|
588
|
+
it("priority 1: returns focusedDate when it is in the grid", () => {
|
|
589
|
+
const result = resolveFocusTarget(d("2026-03-15"), undefined, marchWeeks, march, noDisabled, T);
|
|
590
|
+
expect(result.toString()).toBe("2026-03-15");
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it("priority 1: returns focusedDate even if selectedDate differs", () => {
|
|
594
|
+
const result = resolveFocusTarget(
|
|
595
|
+
d("2026-03-10"),
|
|
596
|
+
d("2026-03-20"),
|
|
597
|
+
marchWeeks,
|
|
598
|
+
march,
|
|
599
|
+
noDisabled,
|
|
600
|
+
T,
|
|
601
|
+
);
|
|
602
|
+
expect(result.toString()).toBe("2026-03-10");
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it("priority 2: falls back to selectedDate when focusedDate is not in grid", () => {
|
|
606
|
+
const result = resolveFocusTarget(
|
|
607
|
+
d("2026-04-15"),
|
|
608
|
+
d("2026-03-20"),
|
|
609
|
+
marchWeeks,
|
|
610
|
+
march,
|
|
611
|
+
noDisabled,
|
|
612
|
+
T,
|
|
613
|
+
);
|
|
614
|
+
expect(result.toString()).toBe("2026-03-20");
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it("priority 3: falls back to first enabled day of the month when neither focused nor selected is in grid", () => {
|
|
618
|
+
const result = resolveFocusTarget(
|
|
619
|
+
d("2026-04-15"),
|
|
620
|
+
d("2026-04-20"),
|
|
621
|
+
marchWeeks,
|
|
622
|
+
march,
|
|
623
|
+
noDisabled,
|
|
624
|
+
T,
|
|
625
|
+
);
|
|
626
|
+
expect(result.toString()).toBe("2026-03-01");
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it("priority 3: skips disabled days at the start of the month", () => {
|
|
630
|
+
const disableFirst3 = (dd: Temporal.PlainDate) =>
|
|
631
|
+
dd.year === 2026 && dd.month === 3 && dd.day <= 3;
|
|
632
|
+
const result = resolveFocusTarget(
|
|
633
|
+
d("2026-04-15"),
|
|
634
|
+
undefined,
|
|
635
|
+
marchWeeks,
|
|
636
|
+
march,
|
|
637
|
+
disableFirst3,
|
|
638
|
+
T,
|
|
639
|
+
);
|
|
640
|
+
expect(result.toString()).toBe("2026-03-04");
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
it("priority 2: selected outside-month day in grid is still valid", () => {
|
|
644
|
+
const allDays = marchWeeks.flat();
|
|
645
|
+
const outsideDay = allDays.find((dd) => dd.month !== 3);
|
|
646
|
+
if (!outsideDay) return;
|
|
647
|
+
const result = resolveFocusTarget(
|
|
648
|
+
d("2026-05-01"),
|
|
649
|
+
outsideDay,
|
|
650
|
+
marchWeeks,
|
|
651
|
+
march,
|
|
652
|
+
noDisabled,
|
|
653
|
+
T,
|
|
654
|
+
);
|
|
655
|
+
expect(result.toString()).toBe(outsideDay.toString());
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
it("falls back to first grid day when all current-month days are disabled", () => {
|
|
659
|
+
const allDisabled = (dd: Temporal.PlainDate) => dd.year === 2026 && dd.month === 3;
|
|
660
|
+
const result = resolveFocusTarget(
|
|
661
|
+
d("2026-05-01"),
|
|
662
|
+
undefined,
|
|
663
|
+
marchWeeks,
|
|
664
|
+
march,
|
|
665
|
+
allDisabled,
|
|
666
|
+
T,
|
|
667
|
+
);
|
|
668
|
+
const firstGridDay = marchWeeks[0][0];
|
|
669
|
+
expect(result.toString()).toBe(firstGridDay.toString());
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
it("gridHasFocus=false: selectedDate wins over focusedDate when tabbing into grid", () => {
|
|
673
|
+
const result = resolveFocusTarget(
|
|
674
|
+
d("2026-03-01"),
|
|
675
|
+
d("2026-03-20"),
|
|
676
|
+
marchWeeks,
|
|
677
|
+
march,
|
|
678
|
+
noDisabled,
|
|
679
|
+
T,
|
|
680
|
+
false,
|
|
681
|
+
);
|
|
682
|
+
expect(result.toString()).toBe("2026-03-20");
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it("gridHasFocus=false: focusedDate used as fallback when no selectedDate", () => {
|
|
686
|
+
const result = resolveFocusTarget(
|
|
687
|
+
d("2026-03-10"),
|
|
688
|
+
undefined,
|
|
689
|
+
marchWeeks,
|
|
690
|
+
march,
|
|
691
|
+
noDisabled,
|
|
692
|
+
T,
|
|
693
|
+
false,
|
|
694
|
+
);
|
|
695
|
+
expect(result.toString()).toBe("2026-03-10");
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it("gridHasFocus=true: focusedDate wins over selectedDate (keyboard nav)", () => {
|
|
699
|
+
const result = resolveFocusTarget(
|
|
700
|
+
d("2026-03-01"),
|
|
701
|
+
d("2026-03-20"),
|
|
702
|
+
marchWeeks,
|
|
703
|
+
march,
|
|
704
|
+
noDisabled,
|
|
705
|
+
T,
|
|
706
|
+
true,
|
|
707
|
+
);
|
|
708
|
+
expect(result.toString()).toBe("2026-03-01");
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
describe("shouldMoveDomFocus", () => {
|
|
713
|
+
it.each<{
|
|
714
|
+
description: string;
|
|
715
|
+
isFocused: boolean;
|
|
716
|
+
gridHasFocus: boolean;
|
|
717
|
+
expected: boolean;
|
|
718
|
+
}>([
|
|
719
|
+
{
|
|
720
|
+
description: "focused + grid has focus → true (keyboard nav)",
|
|
721
|
+
isFocused: true,
|
|
722
|
+
gridHasFocus: true,
|
|
723
|
+
expected: true,
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
description: "focused + grid blurred → false (nav button click)",
|
|
727
|
+
isFocused: true,
|
|
728
|
+
gridHasFocus: false,
|
|
729
|
+
expected: false,
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
description: "not focused + grid has focus → false",
|
|
733
|
+
isFocused: false,
|
|
734
|
+
gridHasFocus: true,
|
|
735
|
+
expected: false,
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
description: "not focused + grid blurred → false",
|
|
739
|
+
isFocused: false,
|
|
740
|
+
gridHasFocus: false,
|
|
741
|
+
expected: false,
|
|
742
|
+
},
|
|
743
|
+
])("$description", ({ isFocused, gridHasFocus, expected }) => {
|
|
744
|
+
expect(shouldMoveDomFocus(isFocused, gridHasFocus)).toBe(expected);
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
describe.each(temporalVariants)("isInRange ($name)", ({ T }) => {
|
|
749
|
+
const d = (iso: string) => T.PlainDate.from(iso);
|
|
750
|
+
const start = d("2026-03-10");
|
|
751
|
+
const end = d("2026-03-20");
|
|
752
|
+
|
|
753
|
+
it.each<{
|
|
754
|
+
description: string;
|
|
755
|
+
d: string;
|
|
756
|
+
s: string;
|
|
757
|
+
e: string;
|
|
758
|
+
expected: number | false;
|
|
759
|
+
}>([
|
|
760
|
+
{
|
|
761
|
+
description: "before range",
|
|
762
|
+
d: "2026-03-05",
|
|
763
|
+
s: "2026-03-10",
|
|
764
|
+
e: "2026-03-20",
|
|
765
|
+
expected: false,
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
description: "at range start (inclusive)",
|
|
769
|
+
d: "2026-03-10",
|
|
770
|
+
s: "2026-03-10",
|
|
771
|
+
e: "2026-03-20",
|
|
772
|
+
expected: 0,
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
description: "middle of range",
|
|
776
|
+
d: "2026-03-15",
|
|
777
|
+
s: "2026-03-10",
|
|
778
|
+
e: "2026-03-20",
|
|
779
|
+
expected: 0.5,
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
description: "at range end (inclusive)",
|
|
783
|
+
d: "2026-03-20",
|
|
784
|
+
s: "2026-03-10",
|
|
785
|
+
e: "2026-03-20",
|
|
786
|
+
expected: 1,
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
description: "after range",
|
|
790
|
+
d: "2026-03-25",
|
|
791
|
+
s: "2026-03-10",
|
|
792
|
+
e: "2026-03-20",
|
|
793
|
+
expected: false,
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
description: "one day before start",
|
|
797
|
+
d: "2026-03-09",
|
|
798
|
+
s: "2026-03-10",
|
|
799
|
+
e: "2026-03-20",
|
|
800
|
+
expected: false,
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
description: "one day after end",
|
|
804
|
+
d: "2026-03-21",
|
|
805
|
+
s: "2026-03-10",
|
|
806
|
+
e: "2026-03-20",
|
|
807
|
+
expected: false,
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
description: "two-day range start endpoint",
|
|
811
|
+
d: "2026-03-10",
|
|
812
|
+
s: "2026-03-10",
|
|
813
|
+
e: "2026-03-11",
|
|
814
|
+
expected: 0,
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
description: "two-day range end endpoint",
|
|
818
|
+
d: "2026-03-11",
|
|
819
|
+
s: "2026-03-10",
|
|
820
|
+
e: "2026-03-11",
|
|
821
|
+
expected: 1,
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
description: "single-day range (start = end = date)",
|
|
825
|
+
d: "2026-03-15",
|
|
826
|
+
s: "2026-03-15",
|
|
827
|
+
e: "2026-03-15",
|
|
828
|
+
expected: 0,
|
|
829
|
+
},
|
|
830
|
+
])("$description", ({ d: dd, s, e, expected }) => {
|
|
831
|
+
expect(isInRange(d(dd), d(s), d(e), T)).toBe(expected);
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
it("returns false when rangeStart is undefined", () => {
|
|
835
|
+
expect(isInRange(d("2026-03-15"), undefined, end, T)).toBe(false);
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
it("returns false when rangeEnd is undefined", () => {
|
|
839
|
+
expect(isInRange(d("2026-03-15"), start, undefined, T)).toBe(false);
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
it("returns false when both are undefined", () => {
|
|
843
|
+
expect(isInRange(d("2026-03-15"), undefined, undefined, T)).toBe(false);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
describe.each(temporalVariants)("computeWeekRangeInfo ($name)", ({ T }) => {
|
|
848
|
+
const d = (iso: string) => T.PlainDate.from(iso);
|
|
849
|
+
const marchWeeks = getMonthWeeks(2026, 3, T);
|
|
850
|
+
const week1 = marchWeeks[1];
|
|
851
|
+
|
|
852
|
+
it("treats undefined rangeStart as single-day range at rangeEnd", () => {
|
|
853
|
+
const result = computeWeekRangeInfo(week1, undefined, d("2026-03-10"), T);
|
|
854
|
+
expect(result.active).toBe(true);
|
|
855
|
+
expect(result.startIndex).toBe(2);
|
|
856
|
+
expect(result.endIndex).toBe(2);
|
|
857
|
+
expect(result.extendsBefore).toBe(false);
|
|
858
|
+
expect(result.extendsAfter).toBe(false);
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it("treats undefined rangeEnd as single-day range at rangeStart", () => {
|
|
862
|
+
const result = computeWeekRangeInfo(week1, d("2026-03-11"), undefined, T);
|
|
863
|
+
expect(result.active).toBe(true);
|
|
864
|
+
expect(result.startIndex).toBe(3);
|
|
865
|
+
expect(result.endIndex).toBe(3);
|
|
866
|
+
expect(result.extendsBefore).toBe(false);
|
|
867
|
+
expect(result.extendsAfter).toBe(false);
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
it("returns inactive when range has no overlap with week", () => {
|
|
871
|
+
const result = computeWeekRangeInfo(week1, d("2026-04-01"), d("2026-04-10"), T);
|
|
872
|
+
expect(result.active).toBe(false);
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
it("range fully within week", () => {
|
|
876
|
+
const result = computeWeekRangeInfo(week1, d("2026-03-09"), d("2026-03-12"), T);
|
|
877
|
+
expect(result.active).toBe(true);
|
|
878
|
+
expect(result.extendsBefore).toBe(false);
|
|
879
|
+
expect(result.extendsAfter).toBe(false);
|
|
880
|
+
const startDay = week1[result.startIndex];
|
|
881
|
+
const endDay = week1[result.endIndex];
|
|
882
|
+
expect(startDay.toString()).toBe("2026-03-09");
|
|
883
|
+
expect(endDay.toString()).toBe("2026-03-12");
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
it("range starts before week", () => {
|
|
887
|
+
const result = computeWeekRangeInfo(week1, d("2026-03-01"), d("2026-03-12"), T);
|
|
888
|
+
expect(result.active).toBe(true);
|
|
889
|
+
expect(result.extendsBefore).toBe(true);
|
|
890
|
+
expect(result.extendsAfter).toBe(false);
|
|
891
|
+
expect(result.startIndex).toBe(0);
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
it("range ends after week", () => {
|
|
895
|
+
const result = computeWeekRangeInfo(week1, d("2026-03-09"), d("2026-03-25"), T);
|
|
896
|
+
expect(result.active).toBe(true);
|
|
897
|
+
expect(result.extendsBefore).toBe(false);
|
|
898
|
+
expect(result.extendsAfter).toBe(true);
|
|
899
|
+
expect(result.endIndex).toBe(week1.length - 1);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
it("range spans entire week", () => {
|
|
903
|
+
const result = computeWeekRangeInfo(week1, d("2026-03-01"), d("2026-03-25"), T);
|
|
904
|
+
expect(result.active).toBe(true);
|
|
905
|
+
expect(result.extendsBefore).toBe(true);
|
|
906
|
+
expect(result.extendsAfter).toBe(true);
|
|
907
|
+
expect(result.startIndex).toBe(0);
|
|
908
|
+
expect(result.endIndex).toBe(week1.length - 1);
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
it("single-day range within week", () => {
|
|
912
|
+
const singleDay = d("2026-03-10");
|
|
913
|
+
const result = computeWeekRangeInfo(week1, singleDay, singleDay, T);
|
|
914
|
+
expect(result.active).toBe(true);
|
|
915
|
+
expect(result.startIndex).toBe(result.endIndex);
|
|
916
|
+
expect(result.extendsBefore).toBe(false);
|
|
917
|
+
expect(result.extendsAfter).toBe(false);
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
it("two-day range within week", () => {
|
|
921
|
+
const result = computeWeekRangeInfo(week1, d("2026-03-10"), d("2026-03-11"), T);
|
|
922
|
+
expect(result.active).toBe(true);
|
|
923
|
+
expect(result.endIndex - result.startIndex).toBe(1);
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
it("returns inactive for empty weekDays array", () => {
|
|
927
|
+
const result = computeWeekRangeInfo([], d("2026-03-10"), d("2026-03-15"), T);
|
|
928
|
+
expect(result.active).toBe(false);
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
describe.each(temporalVariants)("getISOWeekNumber ($name)", ({ T }) => {
|
|
933
|
+
const d = (iso: string) => T.PlainDate.from(iso);
|
|
934
|
+
|
|
935
|
+
it.each<{
|
|
936
|
+
description: string;
|
|
937
|
+
d: string;
|
|
938
|
+
expected: number;
|
|
939
|
+
}>([
|
|
940
|
+
{
|
|
941
|
+
description: "Jan 1, 2026 (Thursday) → week 1",
|
|
942
|
+
d: "2026-01-01",
|
|
943
|
+
expected: 1,
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
description: "Jan 4, 2026 (Sunday) → week 1",
|
|
947
|
+
d: "2026-01-04",
|
|
948
|
+
expected: 1,
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
description: "Jan 5, 2026 (Monday) → week 2",
|
|
952
|
+
d: "2026-01-05",
|
|
953
|
+
expected: 2,
|
|
954
|
+
},
|
|
955
|
+
{
|
|
956
|
+
description: "Dec 31, 2026 (Thursday) → week 53",
|
|
957
|
+
d: "2026-12-31",
|
|
958
|
+
expected: 53,
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
description: "Dec 28, 2025 (Sunday) → week 52 of 2025",
|
|
962
|
+
d: "2025-12-28",
|
|
963
|
+
expected: 52,
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
description: "Dec 29, 2025 (Monday) → week 1 of 2026",
|
|
967
|
+
d: "2025-12-29",
|
|
968
|
+
expected: 1,
|
|
969
|
+
},
|
|
970
|
+
{
|
|
971
|
+
description: "Mar 15, 2026 (Sunday) → week 11",
|
|
972
|
+
d: "2026-03-15",
|
|
973
|
+
expected: 11,
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
description: "Jun 1, 2026 (Monday) → week 23",
|
|
977
|
+
d: "2026-06-01",
|
|
978
|
+
expected: 23,
|
|
979
|
+
},
|
|
980
|
+
])("$description", ({ d: dd, expected }) => {
|
|
981
|
+
expect(getISOWeekNumber(d(dd), T)).toBe(expected);
|
|
982
|
+
});
|
|
983
|
+
});
|