Files
vu/src/calendar/temporal-id.ts
T
will 37ac31c3f2
Deploy / deploy (push) Successful in 39s
calendar: occurrence engine v2 — real rank thresholds, transfers, collisions
Corrects and completes the occurrence rules, based on a design discussion
plus one concrete data point: St. Anthony Abbot (plain Duplex) was found
outright winning against an ordinary Sunday in the real Monastic 1617
engine, which the old duplex-1-classis-only threshold got wrong.

- FeastClass gains `vigil`, inserted between `simplex` and `semiduplex` —
  one ordering that correctly serves both "does this win against a Sunday"
  (vigil behaves like simplex there) and "which of two saints wins a
  landing-day collision" (vigil beats simplex, loses to semiduplex).
- LiturgicalDay.occurring (a flat OccurringFeast[] that could only ever
  express a losing *sanctoral* candidate) is replaced by `winner:
  DayWinner` + `commemorations: Commemoration[]` — a discriminated list
  that can hold the temporal day itself, one or more sanctoral entries, or
  (not built yet, but the shape already accommodates it) a future octave
  kind.
- commemorations.ts: ordinary Sundays let Duplex+ win outright (Sunday
  commemorated in return), Semiduplex/Vigil transfer elsewhere (too
  substantial a feast to cheapen with a bare commemoration), Simplex stays
  and is commemorated. Privileged Sundays never displace; Duplex-majus+
  commemorated, everything else transfers.
- collision.ts (new): resolves two sanctoral candidates wanting the same
  day (a transfer landing on an already-occupied day, or two native
  saints sharing a date) — duplex > semiduplex > vigil > simplex, loser
  always commemorated, ties favor the native occupant.
- temporal-id.ts (new): maps any date to one of the 52 real Sunday-collect
  ids from the previous commit, so a temporal winner/commemoration can
  actually be looked up, not just labeled "temporal" in the abstract.
- index.ts's resolveDay orchestrates all of it, including the actual
  Monday/Saturday transfer mechanism. Landing on a privileged feria (the
  concrete case: Holy Week, right after Palm Sunday) is explicitly
  deferred rather than guessed at — it needs its own Easter-keyed lookup
  table, the same way the reference engine handles it.

Added the Vigil of St. Lawrence (Aug 9) as real content specifically to
exercise the backward-transfer rule end-to-end: Aug 9, 2026 is a Sunday,
so the vigil transfers cleanly back to Saturday, verified by a new
integration test alongside the unit-level rule and collision tests.
2026-08-10 12:00:01 -04:00

87 lines
3.5 KiB
TypeScript

// Maps any date to one of the 52 canonical temporal-propers ids already
// authored in data/propers/temporal/*.yml — the "which Sunday's collect
// governs this date" question. A feria always inherits the collect of the
// Sunday on or before it (real rubric: the ferias of a week use that
// week's own Sunday collect), so this is really "find the governing
// Sunday, then name it."
//
// Deliberately Pentecost/offset-based, not Trinity-counted — this is
// content-storage identity, kept independent of whatever counting
// convention calendar/day-label.ts displays on screen. See that file's
// header and propers/index.ts's getTemporalProper for the fuller version
// of this reasoning.
//
// Two known, deliberately unfixed gaps: the ferias between Christmas Day
// and the Sunday within its octave, and between Epiphany and its own
// first Sunday, fall back to that season's first named Sunday a few days
// early — Christmas Day's and Epiphany's own collects aren't authored as
// separate temporal-propers entries (only Sunday collects were pulled), so
// this is a deliberate approximation, not an oversight. Likewise, a real
// overflow year (early Easter, more than 24 weeks between Trinity and
// Advent) would traditionally reuse the unused post-Epiphany Sundays'
// collects for the excess weeks — not modeled; this just clamps at
// post-pentecost-24.
import { resolveSeason, sundayOnOrBefore, firstSundayStrictlyAfter, adventStart, easterOffsetOf } from './temporal';
import { daysBetween } from './date-math';
const EASTER_OFFSET_IDS: [number, string][] = [
[-63, 'septuagesima'],
[-56, 'sexagesima'],
[-49, 'quinquagesima'],
[-42, 'lent-1'],
[-35, 'lent-2'],
[-28, 'lent-3'],
[-21, 'lent-4'],
[-14, 'passion-sunday'],
[-7, 'palm-sunday'],
[0, 'easter-sunday'],
[7, 'easter-octave'],
[14, 'easter-3'],
[21, 'easter-4'],
[28, 'easter-5'],
[35, 'easter-6'],
[42, 'sunday-after-ascension'],
[49, 'pentecost-sunday'],
];
for (let n = 1; n <= 24; n++) {
EASTER_OFFSET_IDS.push([56 + 7 * (n - 1), `post-pentecost-${String(n).padStart(2, '0')}`]);
}
const EASTER_OFFSET_ID_MAP = new Map(EASTER_OFFSET_IDS);
const MAX_EASTER_OFFSET = EASTER_OFFSET_IDS[EASTER_OFFSET_IDS.length - 1]![0];
const MAX_EASTER_OFFSET_ID = EASTER_OFFSET_IDS[EASTER_OFFSET_IDS.length - 1]![1];
export function resolveTemporalId(isoDate: string): string {
const season = resolveSeason(isoDate);
const year = Number(isoDate.slice(0, 4));
if (season === 'advent') {
const start = adventStart(year);
const n = Math.round(daysBetween(start, sundayOnOrBefore(isoDate)) / 7) + 1;
return `advent-${Math.min(n, 4)}`;
}
if (season === 'christmastide') {
return 'christmas-octave-sunday';
}
if (season === 'epiphanytide') {
const firstSunday = firstSundayStrictlyAfter(`${year}-01-06`);
if (isoDate < firstSunday) {
return 'post-epiphany-1';
}
const n = Math.round(daysBetween(firstSunday, sundayOnOrBefore(isoDate)) / 7) + 1;
return `post-epiphany-${Math.min(n, 6)}`;
}
// Everything else (Septuagesima-tide through Trinitytide) is Easter-
// anchored — find the governing Sunday and map its own offset directly,
// regardless of which `season` bucket the feria itself falls in (the
// ferias right after Ash Wednesday genuinely reuse Quinquagesima's
// collect, crossing what resolveSeason calls two different seasons).
const offset = easterOffsetOf(sundayOnOrBefore(isoDate));
if (offset > MAX_EASTER_OFFSET) {
return MAX_EASTER_OFFSET_ID;
}
return EASTER_OFFSET_ID_MAP.get(offset) ?? 'septuagesima';
}