export function toDayKey(date: Date): string { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); const d = String(date.getDate()).padStart(2, "0"); return `${y}-${m}-${d}`; } export function recordedDayKey(iso: string): string { return toDayKey(new Date(iso)); } export function dayKeyToMonthStart(dayKey: string): Date | null { const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dayKey); if (!match) return null; return new Date(Number(match[1]), Number(match[2]) - 1, 1); } export function formatDayKeyLabel(dayKey: string): string { const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dayKey); if (!match) return dayKey; const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3])); return date.toLocaleDateString(undefined, { month: "long", day: "numeric", year: "numeric" }); } export function buildEntryDaySet(entries: Array<{ recordedAt: string }>): Set { return new Set(entries.map((entry) => recordedDayKey(entry.recordedAt))); }