calendar: occurrence engine v2 — real rank thresholds, transfers, collisions
Deploy / deploy (push) Successful in 39s

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.
This commit is contained in:
2026-08-10 12:00:01 -04:00
parent 8bb5d0167d
commit 37ac31c3f2
23 changed files with 573 additions and 198 deletions
+40
View File
@@ -0,0 +1,40 @@
// Resolves two sanctoral candidates wanting the same day — the case
// calendar/feasts.ts explicitly doesn't cover (it just picks the
// higher-ranked of several native candidates and drops the rest) and that
// calendar/commemorations.ts doesn't cover either (that's temporal-vs-
// sanctoral, this is sanctoral-vs-sanctoral). This is specifically what a
// transferred feast (calendar/transfer.ts) runs into when its landing day
// already has a native saint — never triggered by a plain ferial landing,
// since a genuinely empty day isn't a collision at all.
//
// Same ordering as commemorations.ts's FeastClass scale, which is exactly
// the point: `duplex > semiduplex > vigil > simplex` is that scale, not a
// separate one — see calendar/types.ts's FeastClass doc comment.
import type { Commemoration, DayWinner, SanctoralIdentity } from './types';
import { compareFeastClass } from './commemorations';
export interface CollisionResult {
winner: DayWinner;
commemorations: Commemoration[];
}
function asWinner(candidate: SanctoralIdentity): DayWinner {
return { kind: 'sanctoral', id: candidate.id, name: candidate.name, rank: candidate.rank };
}
function asCommemoration(candidate: SanctoralIdentity): Commemoration {
return { kind: 'sanctoral', id: candidate.id, name: candidate.name, rank: candidate.rank };
}
/**
* `incoming` is the transferred candidate; `native` is whoever already
* occupies the landing day. The loser is always commemorated — unlike
* commemorations.ts's Sunday rules, there's no rank threshold below which
* it gets nothing; a real named feast landing anywhere always leaves a
* trace. Ties favor `native` — the incoming feast is the guest here.
*/
export function resolveCollision(incoming: SanctoralIdentity, native: SanctoralIdentity): CollisionResult {
const winner = compareFeastClass(incoming.rank, native.rank) > 0 ? incoming : native;
const loser = winner === incoming ? native : incoming;
return { winner: asWinner(winner), commemorations: [asCommemoration(loser)] };
}