Files
vu/src/calendar/date-math.ts
T
will ad87d8dd18
Deploy / deploy (push) Successful in 37s
calendar: move Sunday-governance arithmetic from day-label.ts into temporal.ts
sundayOnOrBefore and firstSundayStrictlyAfter are calendar facts ("which
Sunday does this feria belong to"), not presentation logic — day-label.ts
was the only consumer so far, but a future temporal-propers content
resolver (PropersRef's still-unused source: 'temporal' branch) will need
the exact same arithmetic, just keyed for content ids instead of display
strings. Moving it now, while the shape is still small and well
understood, rather than duplicating it later.

day-label.ts keeps the actual display config (which anchor, "Trinity" vs
"Pentecost" wording) — that part stays presentation-only on purpose, since
it's also where a future counting-convention setting would hook in.

No behavior change: 88/88 tests still pass.
2026-08-10 07:30:21 -04:00

33 lines
1.1 KiB
TypeScript

// Small ISO-date ("YYYY-MM-DD") arithmetic helpers shared by easter.ts and
// temporal.ts. Parsed/formatted as UTC midnight throughout, same convention
// as weekday.ts, so results don't shift with the caller's local timezone.
export interface CalendarDate {
year: number;
month: number; // 1-12
day: number;
}
export function toIsoDate(date: CalendarDate): string {
const mm = String(date.month).padStart(2, '0');
const dd = String(date.day).padStart(2, '0');
return `${date.year}-${mm}-${dd}`;
}
export function addDays(isoDate: string, days: number): string {
const d = new Date(`${isoDate}T00:00:00Z`);
d.setUTCDate(d.getUTCDate() + days);
return d.toISOString().slice(0, 10);
}
export function daysBetween(fromIsoDate: string, toIsoDate: string): number {
const from = new Date(`${fromIsoDate}T00:00:00Z`).getTime();
const to = new Date(`${toIsoDate}T00:00:00Z`).getTime();
return Math.round((to - from) / 86_400_000);
}
/** 0 = Sunday, ..., 6 = Saturday. */
export function dayOfWeek(isoDate: string): number {
return new Date(`${isoDate}T00:00:00Z`).getUTCDay();
}