From f68d16ef58e3ff841bba6d5573e752d7e1ec8e92 Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 8 May 2026 11:28:58 +0200 Subject: [PATCH] docs(documents): explain monthBoundaryTo day-zero idiom (#385) Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/lib/document/timeline.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/src/lib/document/timeline.ts b/frontend/src/lib/document/timeline.ts index 0653ea99..bc9dcacb 100644 --- a/frontend/src/lib/document/timeline.ts +++ b/frontend/src/lib/document/timeline.ts @@ -18,6 +18,9 @@ export function monthBoundaryFrom(yearMonth: string): string { export function monthBoundaryTo(yearMonth: string): string { const [year, month] = yearMonth.split('-').map(Number); + // Day 0 of `month + 1` rolls back to the last day of `month` — so passing + // `month` (1-indexed) into `Date.UTC(year, month, 0)` lands on the last day + // of that month. Handles 28/29/30/31 and leap years without a lookup table. const lastDay = new Date(Date.UTC(year, month, 0)).getUTCDate(); return `${yearMonth}-${String(lastDay).padStart(2, '0')}`; }