diff --git a/web/src/lib/event.test.ts b/web/src/lib/event.test.ts index d48b491..540552c 100644 --- a/web/src/lib/event.test.ts +++ b/web/src/lib/event.test.ts @@ -78,6 +78,27 @@ describe("organizeEventsInCalendar", () => { expect(week["2026-07-12"]).toEqual([]); }); + it("drops a leading month that only contains seeded padding days", () => { + // tirsdag 1. september 2026: the seeded week starts mandag 31. august + const events = getSingularEvents([ + makeEvent("a", ["2026-09-04T17:00:00Z"]), + makeEvent("b", ["2026-10-02T17:00:00Z"]), + ]); + + const calendar = organizeEventsInCalendar(events); + + expect(Object.keys(calendar)).toEqual(["2026-09", "2026-10"]); + // the first week is still seeded with its September days + expect(Object.keys(calendar["2026-09"]["36"])).toEqual([ + "2026-09-01", + "2026-09-02", + "2026-09-03", + "2026-09-04", + "2026-09-05", + "2026-09-06", + ]); + }); + it("splits a week across the year boundary under a shared week key", () => { const events = getSingularEvents([ makeEvent("romjul", ["2026-12-30T20:00:00Z"]), diff --git a/web/src/lib/event.ts b/web/src/lib/event.ts index 5eb9529..b4573d1 100644 --- a/web/src/lib/event.ts +++ b/web/src/lib/event.ts @@ -314,6 +314,19 @@ export function organizeEventsInCalendar( calendar[yearMonth][week][day].push(event); }); + // Seeding starts at the Monday of the first event's week, which can spill a + // few empty days into the previous month. Drop that leading empty month so + // the calendar starts at the first month that actually has events. + for (const yearMonth of Object.keys(calendar)) { + const hasEvents = Object.values(calendar[yearMonth]).some((week) => + Object.values(week).some((day) => day.length > 0) + ); + if (hasEvents) { + break; + } + delete calendar[yearMonth]; + } + return calendar; }