Spaces:
Sleeping
Sleeping
File size: 1,266 Bytes
391340f 709db16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /** 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));
}
|