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')}`; }