/** Local-date helpers for daily strips (no UTC drift). */ export function isoDate(d: Date): string { const y = d.getFullYear(); const m = String(d.getMonth() + 1).padStart(2, "0"); const day = String(d.getDate()).padStart(2, "0"); return `${y}-${m}-${day}`; } /** Last `n` calendar days ending at `end`, oldest first. */ export function lastNDays(end: Date, n: number): string[] { const days: string[] = []; for (let i = n - 1; i >= 0; i -= 1) { const d = new Date(end.getFullYear(), end.getMonth(), end.getDate() - i); days.push(isoDate(d)); } return days; } /** * Local Monday–Sunday calendar week containing `anchor`. * Week points on Home use this window (not a rolling 7 ending today). */ export function mondaySundayWeek(anchor: Date = new Date()): string[] { const local = new Date(anchor.getFullYear(), anchor.getMonth(), anchor.getDate()); const day = local.getDay(); // 0 Sun … 6 Sat const mondayOffset = day === 0 ? -6 : 1 - day; const monday = new Date(local.getFullYear(), local.getMonth(), local.getDate() + mondayOffset); return lastNDays(new Date(monday.getFullYear(), monday.getMonth(), monday.getDate() + 6), 7); } export function entryLocalDate(ts: string): string { return isoDate(new Date(ts)); }