@jsb188/calendar 1.1.2

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.
@@ -0,0 +1,340 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ getCalendarCreateRange,
4
+ getCalendarMoveRange,
5
+ getCalendarPointerSlot,
6
+ getCalendarResizeRange,
7
+ } from '../src/libs/calendar-gesture.ts';
8
+ import {
9
+ getCalendarRange,
10
+ parseCalendarDateParam,
11
+ } from '../src/libs/calendar-range.ts';
12
+
13
+ const LA = 'America/Los_Angeles';
14
+ const NOW = new Date('2026-07-22T19:00:00Z');
15
+
16
+ function buildWeek() {
17
+ return getCalendarRange({
18
+ view: 'WEEK',
19
+ anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
20
+ now: NOW,
21
+ timeZone: LA,
22
+ });
23
+ }
24
+
25
+ /*
26
+ * The DST fall-back day, which is 25 hours long.
27
+ */
28
+
29
+ function buildFallBackDay() {
30
+ return getCalendarRange({
31
+ view: 'DAY',
32
+ anchorDate: parseCalendarDateParam('2026-11-01', NOW, LA),
33
+ now: NOW,
34
+ timeZone: LA,
35
+ });
36
+ }
37
+
38
+ describe('getCalendarPointerSlot', () => {
39
+ it('maps a pointer to its day column and snapped minute', () => {
40
+ const week = buildWeek();
41
+ // Fourth of seven columns, 9.5 hours down at 48px/hour
42
+ const slot = getCalendarPointerSlot({
43
+ offsetX: 700 * (3 / 7) + 10,
44
+ offsetY: 9.5 * 48,
45
+ contentWidth: 700,
46
+ hourHeight: 48,
47
+ days: week.days,
48
+ });
49
+
50
+ expect(slot.dayIndex).toBe(3);
51
+ expect(slot.minute).toBe(9 * 60 + 30);
52
+ });
53
+
54
+ it('snaps to the nearest quarter hour', () => {
55
+ const week = buildWeek();
56
+ const slot = getCalendarPointerSlot({
57
+ offsetX: 10,
58
+ // 9h07m — closer to 9:00 than to 9:15
59
+ offsetY: (9 + 7 / 60) * 48,
60
+ contentWidth: 700,
61
+ hourHeight: 48,
62
+ days: week.days,
63
+ });
64
+
65
+ expect(slot.minute).toBe(9 * 60);
66
+ });
67
+
68
+ it('clamps a pointer dragged outside the grid', () => {
69
+ const week = buildWeek();
70
+
71
+ expect(
72
+ getCalendarPointerSlot({
73
+ offsetX: -50,
74
+ offsetY: -100,
75
+ contentWidth: 700,
76
+ hourHeight: 48,
77
+ days: week.days,
78
+ }),
79
+ ).toEqual({ dayIndex: 0, minute: 0 });
80
+ expect(
81
+ getCalendarPointerSlot({
82
+ offsetX: 9999,
83
+ offsetY: 99999,
84
+ contentWidth: 700,
85
+ hourHeight: 48,
86
+ days: week.days,
87
+ }),
88
+ ).toEqual({ dayIndex: 6, minute: 24 * 60 });
89
+ });
90
+ });
91
+
92
+ describe('getCalendarCreateRange', () => {
93
+ it('makes a default-length event from a click that never moved', () => {
94
+ const week = buildWeek();
95
+ const range = getCalendarCreateRange({
96
+ days: week.days,
97
+ anchorDayIndex: 3,
98
+ anchorMinute: 9 * 60,
99
+ currentDayIndex: 3,
100
+ currentMinute: 9 * 60,
101
+ moved: false,
102
+ });
103
+
104
+ // A click must not produce a zero-length event
105
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(60 * 60_000);
106
+ expect(range.startAt.toISOString()).toBe('2026-07-22T16:00:00.000Z');
107
+ });
108
+
109
+ it('draws the dragged range', () => {
110
+ const week = buildWeek();
111
+ const range = getCalendarCreateRange({
112
+ days: week.days,
113
+ anchorDayIndex: 3,
114
+ anchorMinute: 9 * 60,
115
+ currentDayIndex: 3,
116
+ currentMinute: 12 * 60,
117
+ moved: true,
118
+ });
119
+
120
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
121
+ 3 * 60 * 60_000,
122
+ );
123
+ });
124
+
125
+ it('accepts a drag drawn upward', () => {
126
+ const week = buildWeek();
127
+ const range = getCalendarCreateRange({
128
+ days: week.days,
129
+ anchorDayIndex: 3,
130
+ anchorMinute: 12 * 60,
131
+ currentDayIndex: 3,
132
+ currentMinute: 9 * 60,
133
+ moved: true,
134
+ });
135
+
136
+ expect(range.startAt.toISOString()).toBe('2026-07-22T16:00:00.000Z');
137
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
138
+ 3 * 60 * 60_000,
139
+ );
140
+ });
141
+
142
+ it('gives a barely-moved drag the minimum length', () => {
143
+ const week = buildWeek();
144
+ const range = getCalendarCreateRange({
145
+ days: week.days,
146
+ anchorDayIndex: 3,
147
+ anchorMinute: 9 * 60,
148
+ currentDayIndex: 3,
149
+ currentMinute: 9 * 60,
150
+ moved: true,
151
+ });
152
+
153
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(20 * 60_000);
154
+ });
155
+
156
+ it('stays in the column it began in', () => {
157
+ const week = buildWeek();
158
+ // A sideways wobble while drawing is not a request for a multi-day event
159
+ const range = getCalendarCreateRange({
160
+ days: week.days,
161
+ anchorDayIndex: 3,
162
+ anchorMinute: 9 * 60,
163
+ currentDayIndex: 5,
164
+ currentMinute: 12 * 60,
165
+ moved: true,
166
+ });
167
+
168
+ expect(range.dayIndex).toBe(3);
169
+ expect(range.startAt.toISOString()).toBe('2026-07-22T16:00:00.000Z');
170
+ });
171
+
172
+ it('does not run a click off the end of the day', () => {
173
+ const week = buildWeek();
174
+ const range = getCalendarCreateRange({
175
+ days: week.days,
176
+ anchorDayIndex: 3,
177
+ anchorMinute: 24 * 60,
178
+ currentDayIndex: 3,
179
+ currentMinute: 24 * 60,
180
+ moved: false,
181
+ });
182
+
183
+ expect(range.endAt.getTime()).toBeLessThanOrEqual(
184
+ week.days[3].endAt.getTime(),
185
+ );
186
+ });
187
+ });
188
+
189
+ describe('getCalendarMoveRange', () => {
190
+ it('preserves duration and honours the grab offset', () => {
191
+ const week = buildWeek();
192
+ const startAt = new Date('2026-07-22T16:00:00Z');
193
+ const endAt = new Date('2026-07-22T20:00:00Z');
194
+
195
+ // Grabbed one hour into the block, dropped with the pointer at 14:00
196
+ const range = getCalendarMoveRange({
197
+ days: week.days,
198
+ startAt,
199
+ endAt,
200
+ grabOffsetMinutes: 60,
201
+ currentDayIndex: 3,
202
+ currentMinute: 14 * 60,
203
+ });
204
+
205
+ // The block starts an hour before the pointer, not at it
206
+ expect(range.startAt.toISOString()).toBe('2026-07-22T20:00:00.000Z');
207
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
208
+ 4 * 60 * 60_000,
209
+ );
210
+ });
211
+
212
+ it('moves an event to another day', () => {
213
+ const week = buildWeek();
214
+ const range = getCalendarMoveRange({
215
+ days: week.days,
216
+ startAt: new Date('2026-07-22T16:00:00Z'),
217
+ endAt: new Date('2026-07-22T18:00:00Z'),
218
+ grabOffsetMinutes: 0,
219
+ currentDayIndex: 5,
220
+ currentMinute: 9 * 60,
221
+ });
222
+
223
+ expect(range.dayIndex).toBe(5);
224
+ expect(range.startAt.toISOString()).toBe('2026-07-24T16:00:00.000Z');
225
+ });
226
+
227
+ it('clamps so a drag cannot push an event past midnight', () => {
228
+ const week = buildWeek();
229
+ const range = getCalendarMoveRange({
230
+ days: week.days,
231
+ startAt: new Date('2026-07-22T16:00:00Z'),
232
+ endAt: new Date('2026-07-22T20:00:00Z'),
233
+ grabOffsetMinutes: 0,
234
+ currentDayIndex: 3,
235
+ // Dropped at 23:00 — a 4-hour block would spill into the next day
236
+ currentMinute: 23 * 60,
237
+ });
238
+
239
+ expect(range.endAt.getTime()).toBeLessThanOrEqual(
240
+ week.days[3].endAt.getTime(),
241
+ );
242
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
243
+ 4 * 60 * 60_000,
244
+ );
245
+ });
246
+
247
+ it('keeps a shift the same number of hours across a DST day', () => {
248
+ const day = buildFallBackDay();
249
+ const startAt = new Date('2026-11-01T15:00:00Z');
250
+ const endAt = new Date('2026-11-01T19:00:00Z');
251
+
252
+ const range = getCalendarMoveRange({
253
+ days: day.days,
254
+ startAt,
255
+ endAt,
256
+ grabOffsetMinutes: 0,
257
+ currentDayIndex: 0,
258
+ currentMinute: 10 * 60,
259
+ });
260
+
261
+ // Four hours of actual work stays four hours, even on a 25-hour day
262
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(
263
+ 4 * 60 * 60_000,
264
+ );
265
+ });
266
+ });
267
+
268
+ describe('getCalendarResizeRange', () => {
269
+ it('moves the end edge and leaves the start alone', () => {
270
+ const week = buildWeek();
271
+ const startAt = new Date('2026-07-22T16:00:00Z');
272
+ const endAt = new Date('2026-07-22T18:00:00Z');
273
+
274
+ const range = getCalendarResizeRange({
275
+ days: week.days,
276
+ dayIndex: 3,
277
+ startAt,
278
+ endAt,
279
+ edge: 'END',
280
+ currentMinute: 15 * 60,
281
+ });
282
+
283
+ expect(range.startAt.toISOString()).toBe(startAt.toISOString());
284
+ expect(range.endAt.toISOString()).toBe('2026-07-22T22:00:00.000Z');
285
+ });
286
+
287
+ it('moves the start edge and leaves the end alone', () => {
288
+ const week = buildWeek();
289
+ const startAt = new Date('2026-07-22T16:00:00Z');
290
+ const endAt = new Date('2026-07-22T18:00:00Z');
291
+
292
+ const range = getCalendarResizeRange({
293
+ days: week.days,
294
+ dayIndex: 3,
295
+ startAt,
296
+ endAt,
297
+ edge: 'START',
298
+ currentMinute: 8 * 60,
299
+ });
300
+
301
+ expect(range.startAt.toISOString()).toBe('2026-07-22T15:00:00.000Z');
302
+ expect(range.endAt.toISOString()).toBe(endAt.toISOString());
303
+ });
304
+
305
+ it('refuses to invert the event', () => {
306
+ const week = buildWeek();
307
+ const startAt = new Date('2026-07-22T16:00:00Z');
308
+ const endAt = new Date('2026-07-22T18:00:00Z');
309
+
310
+ // Dragging the end edge above the start
311
+ const range = getCalendarResizeRange({
312
+ days: week.days,
313
+ dayIndex: 3,
314
+ startAt,
315
+ endAt,
316
+ edge: 'END',
317
+ currentMinute: 2 * 60,
318
+ });
319
+
320
+ expect(range.endAt.getTime()).toBeGreaterThan(range.startAt.getTime());
321
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(20 * 60_000);
322
+ });
323
+
324
+ it('refuses to collapse the event from the start edge', () => {
325
+ const week = buildWeek();
326
+ const startAt = new Date('2026-07-22T16:00:00Z');
327
+ const endAt = new Date('2026-07-22T18:00:00Z');
328
+
329
+ const range = getCalendarResizeRange({
330
+ days: week.days,
331
+ dayIndex: 3,
332
+ startAt,
333
+ endAt,
334
+ edge: 'START',
335
+ currentMinute: 20 * 60,
336
+ });
337
+
338
+ expect(range.endAt.getTime() - range.startAt.getTime()).toBe(20 * 60_000);
339
+ });
340
+ });
@@ -0,0 +1,358 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ getCalendarDateKey,
4
+ getCalendarRange,
5
+ getCalendarRangeTitle,
6
+ getCalendarStepAnchor,
7
+ getDayLengthMinutes,
8
+ getInstantFromDayMinutes,
9
+ getMinutesFromDayStart,
10
+ parseCalendarDateParam,
11
+ snapMinutes,
12
+ } from '../src/libs/calendar-range.ts';
13
+
14
+ const LA = 'America/Los_Angeles';
15
+ // A Wednesday
16
+ const NOW = new Date('2026-07-22T19:00:00Z');
17
+
18
+ describe('parseCalendarDateParam', () => {
19
+ it('parses a date param to local midnight in the calendar zone', () => {
20
+ const parsed = parseCalendarDateParam('2026-07-20', NOW, LA);
21
+
22
+ // 2026-07-20T00:00 in Los Angeles is 07:00Z during daylight time
23
+ expect(parsed.toISOString()).toBe('2026-07-20T07:00:00.000Z');
24
+ });
25
+
26
+ it('falls back to today rather than to the epoch', () => {
27
+ const parsed = parseCalendarDateParam('not-a-date', NOW, LA);
28
+
29
+ expect(getCalendarDateKey(parsed, LA)).toBe('2026-07-22');
30
+ });
31
+
32
+ it('resolves "today" in the calendar zone, not in UTC', () => {
33
+ // 2026-07-23T02:00Z is still the 22nd in Los Angeles
34
+ const lateNight = new Date('2026-07-23T02:00:00Z');
35
+
36
+ expect(
37
+ getCalendarDateKey(parseCalendarDateParam(null, lateNight, LA), LA),
38
+ ).toBe('2026-07-22');
39
+ expect(
40
+ getCalendarDateKey(parseCalendarDateParam(null, lateNight, 'UTC'), 'UTC'),
41
+ ).toBe('2026-07-23');
42
+ });
43
+ });
44
+
45
+ describe('getCalendarRange', () => {
46
+ it('builds a Sunday-start week covering the anchor', () => {
47
+ const range = getCalendarRange({
48
+ view: 'WEEK',
49
+ anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
50
+ now: NOW,
51
+ timeZone: LA,
52
+ });
53
+
54
+ expect(range.days).toHaveLength(7);
55
+ expect(range.days[0].dateKey).toBe('2026-07-19');
56
+ expect(range.days[6].dateKey).toBe('2026-07-25');
57
+ expect(range.from.toISOString()).toBe('2026-07-19T07:00:00.000Z');
58
+ expect(range.to.toISOString()).toBe('2026-07-26T07:00:00.000Z');
59
+ });
60
+
61
+ it('honours a Monday week start', () => {
62
+ const range = getCalendarRange({
63
+ view: 'WEEK',
64
+ anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
65
+ now: NOW,
66
+ timeZone: LA,
67
+ weekStartsOn: 1,
68
+ });
69
+
70
+ expect(range.days[0].dateKey).toBe('2026-07-20');
71
+ expect(range.days[6].dateKey).toBe('2026-07-26');
72
+ });
73
+
74
+ it('runs DAY and FOUR_DAYS forward from the anchor', () => {
75
+ const anchor = parseCalendarDateParam('2026-07-22', NOW, LA);
76
+
77
+ expect(
78
+ getCalendarRange({
79
+ view: 'DAY',
80
+ anchorDate: anchor,
81
+ now: NOW,
82
+ timeZone: LA,
83
+ }).days.map((d) => d.dateKey),
84
+ ).toEqual(['2026-07-22']);
85
+ expect(
86
+ getCalendarRange({
87
+ view: 'FOUR_DAYS',
88
+ anchorDate: anchor,
89
+ now: NOW,
90
+ timeZone: LA,
91
+ }).days.map((d) => d.dateKey),
92
+ ).toEqual(['2026-07-22', '2026-07-23', '2026-07-24', '2026-07-25']);
93
+ });
94
+
95
+ it('always builds a six-week month grid, including neighbouring days', () => {
96
+ const range = getCalendarRange({
97
+ view: 'MONTH',
98
+ anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
99
+ now: NOW,
100
+ timeZone: LA,
101
+ });
102
+
103
+ expect(range.days).toHaveLength(42);
104
+ // July 2026 starts on a Wednesday, so the grid opens on Sunday June 28
105
+ expect(range.days[0].dateKey).toBe('2026-06-28');
106
+ expect(range.days[0].isInPrimaryRange).toBe(false);
107
+ expect(
108
+ range.days.find((day) => day.dateKey === '2026-07-01')?.isInPrimaryRange,
109
+ ).toBe(true);
110
+ expect(range.days[41].isInPrimaryRange).toBe(false);
111
+ });
112
+
113
+ it('keeps the month grid six weeks tall even when five would fit', () => {
114
+ // February 2027 starts on a Monday and has 28 days: exactly four weeks
115
+ // from Monday, which a naive grid would render as five rows and then
116
+ // four, making every event jump between months
117
+ const range = getCalendarRange({
118
+ view: 'MONTH',
119
+ anchorDate: parseCalendarDateParam('2027-02-15', NOW, LA),
120
+ now: NOW,
121
+ timeZone: LA,
122
+ weekStartsOn: 1,
123
+ });
124
+
125
+ expect(range.days).toHaveLength(42);
126
+ expect(range.days[0].dateKey).toBe('2027-02-01');
127
+ });
128
+
129
+ it('marks today and weekends in the calendar zone', () => {
130
+ const range = getCalendarRange({
131
+ view: 'WEEK',
132
+ anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
133
+ now: NOW,
134
+ timeZone: LA,
135
+ });
136
+
137
+ expect(
138
+ range.days.filter((day) => day.isToday).map((day) => day.dateKey),
139
+ ).toEqual(['2026-07-22']);
140
+ expect(
141
+ range.days.filter((day) => day.isWeekend).map((day) => day.dateKey),
142
+ ).toEqual(['2026-07-19', '2026-07-25']);
143
+ });
144
+
145
+ it('falls back to a valid zone rather than throwing', () => {
146
+ const range = getCalendarRange({
147
+ view: 'DAY',
148
+ anchorDate: NOW,
149
+ now: NOW,
150
+ timeZone: 'Not/AZone',
151
+ });
152
+
153
+ expect(range.days).toHaveLength(1);
154
+ expect(range.timeZone).toBeTruthy();
155
+ });
156
+ });
157
+
158
+ describe('DST handling', () => {
159
+ it('measures a fall-back day as 25 hours', () => {
160
+ // 2026-11-01 is the US fall-back day
161
+ const range = getCalendarRange({
162
+ view: 'DAY',
163
+ anchorDate: parseCalendarDateParam('2026-11-01', NOW, LA),
164
+ now: NOW,
165
+ timeZone: LA,
166
+ });
167
+
168
+ expect(getDayLengthMinutes(range.days[0])).toBe(25 * 60);
169
+ });
170
+
171
+ it('measures a spring-forward day as 23 hours', () => {
172
+ // 2026-03-08 is the US spring-forward day
173
+ const range = getCalendarRange({
174
+ view: 'DAY',
175
+ anchorDate: parseCalendarDateParam('2026-03-08', NOW, LA),
176
+ now: NOW,
177
+ timeZone: LA,
178
+ });
179
+
180
+ expect(getDayLengthMinutes(range.days[0])).toBe(23 * 60);
181
+ });
182
+
183
+ it('keeps a week containing a transition seven days long', () => {
184
+ const range = getCalendarRange({
185
+ view: 'WEEK',
186
+ anchorDate: parseCalendarDateParam('2026-11-01', NOW, LA),
187
+ now: NOW,
188
+ timeZone: LA,
189
+ });
190
+
191
+ expect(range.days).toHaveLength(7);
192
+ // 25 hours in the first day, 24 in the rest
193
+ expect(range.to.getTime() - range.from.getTime()).toBe(
194
+ (7 * 24 + 1) * 3_600_000,
195
+ );
196
+ });
197
+ });
198
+
199
+ describe('getCalendarStepAnchor', () => {
200
+ it('steps a month view by calendar months, clamping short months', () => {
201
+ const anchor = parseCalendarDateParam('2026-01-31', NOW, LA);
202
+ const next = getCalendarStepAnchor({
203
+ view: 'MONTH',
204
+ anchorDate: anchor,
205
+ direction: 1,
206
+ timeZone: LA,
207
+ });
208
+
209
+ // Stepping from January 31 must land in February, not skip to March
210
+ expect(getCalendarDateKey(next, LA)).toBe('2026-02-28');
211
+ });
212
+
213
+ it('steps week, day and four-day views by their own spans', () => {
214
+ const anchor = parseCalendarDateParam('2026-07-22', NOW, LA);
215
+
216
+ expect(
217
+ getCalendarDateKey(
218
+ getCalendarStepAnchor({
219
+ view: 'WEEK',
220
+ anchorDate: anchor,
221
+ direction: 1,
222
+ timeZone: LA,
223
+ }),
224
+ LA,
225
+ ),
226
+ ).toBe('2026-07-29');
227
+ expect(
228
+ getCalendarDateKey(
229
+ getCalendarStepAnchor({
230
+ view: 'DAY',
231
+ anchorDate: anchor,
232
+ direction: -1,
233
+ timeZone: LA,
234
+ }),
235
+ LA,
236
+ ),
237
+ ).toBe('2026-07-21');
238
+ expect(
239
+ getCalendarDateKey(
240
+ getCalendarStepAnchor({
241
+ view: 'FOUR_DAYS',
242
+ anchorDate: anchor,
243
+ direction: 1,
244
+ timeZone: LA,
245
+ }),
246
+ LA,
247
+ ),
248
+ ).toBe('2026-07-26');
249
+ });
250
+
251
+ it('steps a week across a DST boundary without drifting an hour', () => {
252
+ const anchor = parseCalendarDateParam('2026-10-28', NOW, LA);
253
+ const next = getCalendarStepAnchor({
254
+ view: 'WEEK',
255
+ anchorDate: anchor,
256
+ direction: 1,
257
+ timeZone: LA,
258
+ });
259
+
260
+ // A naive +7*24h would land at 23:00 on the 3rd, which reads as the wrong day
261
+ expect(getCalendarDateKey(next, LA)).toBe('2026-11-04');
262
+ expect(next.toISOString()).toBe('2026-11-04T08:00:00.000Z');
263
+ });
264
+ });
265
+
266
+ describe('minute helpers', () => {
267
+ it('round-trips minutes through a day start', () => {
268
+ const range = getCalendarRange({
269
+ view: 'DAY',
270
+ anchorDate: parseCalendarDateParam('2026-07-22', NOW, LA),
271
+ now: NOW,
272
+ timeZone: LA,
273
+ });
274
+ const dayStart = range.days[0].startAt;
275
+ const instant = getInstantFromDayMinutes(dayStart, 9 * 60 + 30);
276
+
277
+ expect(getMinutesFromDayStart(instant, dayStart)).toBe(9 * 60 + 30);
278
+ expect(instant.toISOString()).toBe('2026-07-22T16:30:00.000Z');
279
+ });
280
+
281
+ it('snaps to the nearest increment and clamps into the day', () => {
282
+ expect(snapMinutes(97, 15, 1440)).toBe(90);
283
+ expect(snapMinutes(103, 15, 1440)).toBe(105);
284
+ expect(snapMinutes(-20, 15, 1440)).toBe(0);
285
+ expect(snapMinutes(2000, 15, 1440)).toBe(1440);
286
+ });
287
+ });
288
+
289
+ describe('getCalendarRangeTitle', () => {
290
+ const anchorFor = (dateKey: string) =>
291
+ parseCalendarDateParam(dateKey, NOW, LA);
292
+
293
+ it('titles a week inside one month', () => {
294
+ const range = getCalendarRange({
295
+ view: 'WEEK',
296
+ anchorDate: anchorFor('2026-07-22'),
297
+ now: NOW,
298
+ timeZone: LA,
299
+ });
300
+
301
+ expect(getCalendarRangeTitle(range)).toBe('Jul 19 – 25, 2026');
302
+ });
303
+
304
+ it('titles a week spanning two months', () => {
305
+ const range = getCalendarRange({
306
+ view: 'WEEK',
307
+ anchorDate: anchorFor('2026-07-30'),
308
+ now: NOW,
309
+ timeZone: LA,
310
+ });
311
+
312
+ expect(getCalendarRangeTitle(range)).toBe('Jul 26 – Aug 1, 2026');
313
+ });
314
+
315
+ it('titles a week spanning two years', () => {
316
+ const range = getCalendarRange({
317
+ view: 'WEEK',
318
+ anchorDate: anchorFor('2026-12-31'),
319
+ now: NOW,
320
+ timeZone: LA,
321
+ });
322
+
323
+ expect(getCalendarRangeTitle(range)).toBe('Dec 27, 2026 – Jan 2, 2027');
324
+ });
325
+
326
+ it('titles month, year and day views', () => {
327
+ expect(
328
+ getCalendarRangeTitle(
329
+ getCalendarRange({
330
+ view: 'MONTH',
331
+ anchorDate: anchorFor('2026-07-22'),
332
+ now: NOW,
333
+ timeZone: LA,
334
+ }),
335
+ ),
336
+ ).toBe('July 2026');
337
+ expect(
338
+ getCalendarRangeTitle(
339
+ getCalendarRange({
340
+ view: 'YEAR',
341
+ anchorDate: anchorFor('2026-07-22'),
342
+ now: NOW,
343
+ timeZone: LA,
344
+ }),
345
+ ),
346
+ ).toBe('2026');
347
+ expect(
348
+ getCalendarRangeTitle(
349
+ getCalendarRange({
350
+ view: 'DAY',
351
+ anchorDate: anchorFor('2026-07-22'),
352
+ now: NOW,
353
+ timeZone: LA,
354
+ }),
355
+ ),
356
+ ).toBe('Wednesday, July 22, 2026');
357
+ });
358
+ });