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
+79 -30
View File
@@ -1,19 +1,24 @@
// Precedence/occurrence resolution: given a day's temporal-cycle standing
// (calendar/types.ts's TemporalCategory) and a candidate sanctoral feast (if
// any), which one is actually kept, and whether the loser is commemorated.
// any), which one is actually kept, what (if anything) is commemorated
// alongside it, and whether the candidate needs to be transferred to an
// adjacent day instead (see calendar/transfer.ts for what actually happens
// with that signal).
//
// Modeled as explicit rules per category, not a numeric-weight comparison
// like the reference engine's occurrence()/concurrence() — see
// data/calendar/temporal-categories.yml's header for why. The thresholds
// below are a best-effort reconstruction of the pre-1955 tradition (partly
// grounded in General Rubrics §15/§16/§23, though that document is itself a
// later, differently-numbered edition — see that file's header), not
// verified against a primary source for this exact era. Expect corrections.
// data/calendar/temporal-categories.yml's header for why. Verified in part
// against real dates (the Sunday-vs-Duplex threshold below was corrected
// after finding St. Anthony Abbot, plain Duplex, outright winning against
// an ordinary Sunday in the real Monastic 1617 engine — a genuine
// correction, not a guess); the rest is the result of a design discussion,
// not yet independently verified against a primary source.
import type { FeastClass, TemporalCategory } from './types';
import type { Commemoration, DayWinner, FeastClass, SanctoralIdentity, TemporalCategory } from './types';
const FEAST_CLASS_ORDER: FeastClass[] = [
'simplex',
'vigil',
'semiduplex',
'duplex',
'duplex-majus',
@@ -29,47 +34,91 @@ export function isAtLeast(rank: FeastClass, threshold: FeastClass): boolean {
return compareFeastClass(rank, threshold) >= 0;
}
/** Vigils belong to the day *before* their feast, so an impeded vigil is
* shifted backward rather than forward like everything else — see
* calendar/transfer.ts. */
function transferDirectionOf(rank: FeastClass): 'forward' | 'backward' {
return rank === 'vigil' ? 'backward' : 'forward';
}
export interface OccurrenceResult {
winner: 'temporal' | 'sanctoral';
commemorated: boolean;
/** This day's own resolution, with the candidate absent if it's being transferred. */
winner: DayWinner;
commemorations: Commemoration[];
/** Set when `sanctoral` doesn't win or get commemorated here at all — it
* needs to be resolved against an adjacent day instead. */
transfer?: { candidate: SanctoralIdentity; direction: 'forward' | 'backward' };
}
function sanctoralCommemoration(candidate: SanctoralIdentity): Commemoration {
return { kind: 'sanctoral', id: candidate.id, name: candidate.name, rank: candidate.rank };
}
function sanctoralWinner(candidate: SanctoralIdentity): DayWinner {
return { kind: 'sanctoral', id: candidate.id, name: candidate.name, rank: candidate.rank };
}
/**
* `sanctoral === null` means no feast is assigned to this date at all —
* temporal wins trivially, nothing to decide.
* `temporalId` is this day's own temporal-propers id (see
* calendar/temporal-id.ts) — needed so a temporal winner or commemoration
* can actually be looked up later (`propers.getTemporalProper`), not just
* named "temporal" in the abstract.
*/
export function decideOccurrence(temporal: TemporalCategory, sanctoral: FeastClass | null): OccurrenceResult {
export function decideOccurrence(
temporal: TemporalCategory,
temporalId: string,
sanctoral: SanctoralIdentity | null,
): OccurrenceResult {
const temporalWinner: DayWinner = { kind: 'temporal', id: temporalId };
if (!sanctoral) {
return { winner: 'temporal', commemorated: false };
return { winner: temporalWinner, commemorations: [] };
}
switch (temporal) {
case 'ordinary-feria':
// An ordinary feria has no standing of its own to defend — any real
// feast, however low-ranked, is kept in its place.
return { winner: 'sanctoral', commemorated: false };
return { winner: sanctoralWinner(sanctoral), commemorations: [] };
case 'privileged-feria':
// "These ferias are preferred to any feasts whatsoever, and they
// admit of no commemoration, except one of the privileged class"
// (General Rubrics §23) — read here as: only the very highest class
// even gets a mention.
return { winner: 'temporal', commemorated: isAtLeast(sanctoral, 'duplex-1-classis') };
// Preferred to any feast whatsoever; admits no commemoration except
// one of the very highest class.
return {
winner: temporalWinner,
commemorations: isAtLeast(sanctoral.rank, 'duplex-1-classis') ? [sanctoralCommemoration(sanctoral)] : [],
};
case 'ordinary-sunday':
// An ordinary Sunday yields outright only to the highest class; a
// Double of the 2nd Class or a Greater Double is kept as a
// commemoration instead of displacing the Sunday; anything lower
// isn't even mentioned.
if (isAtLeast(sanctoral, 'duplex-1-classis')) {
return { winner: 'sanctoral', commemorated: false };
if (isAtLeast(sanctoral.rank, 'duplex')) {
// Duplex+ wins outright; the Sunday itself is commemorated in return.
return { winner: sanctoralWinner(sanctoral), commemorations: [{ kind: 'temporal', id: temporalId }] };
}
return { winner: 'temporal', commemorated: isAtLeast(sanctoral, 'duplex-majus') };
if (sanctoral.rank === 'simplex') {
// Too minor to warrant its own day, but a plain commemoration
// doesn't cheapen it the way it would a Semiduplex.
return { winner: temporalWinner, commemorations: [sanctoralCommemoration(sanctoral)] };
}
// Semiduplex or Vigil: no room here at all, in either direction —
// better to preserve the feast whole on another day than downgrade
// it to a bare commemoration.
return {
winner: temporalWinner,
commemorations: [],
transfer: { candidate: sanctoral, direction: transferDirectionOf(sanctoral.rank) },
};
case 'privileged-sunday':
// "A Sunday of the 1st class is preferred to any feast whatsoever"
// (General Rubrics §15) — never displaced; commemorated only if the
// feast is otherwise of the very top ranks.
return { winner: 'temporal', commemorated: isAtLeast(sanctoral, 'duplex-2-classis') };
if (isAtLeast(sanctoral.rank, 'duplex-majus')) {
// Never displaced, but a sufficiently high feast still gets a nod.
return { winner: temporalWinner, commemorations: [sanctoralCommemoration(sanctoral)] };
}
// Below duplex-majus, a privileged Sunday wants nothing at all —
// not even the bare commemoration an ordinary Sunday would allow a
// Simplex — so everything here transfers.
return {
winner: temporalWinner,
commemorations: [],
transfer: { candidate: sanctoral, direction: transferDirectionOf(sanctoral.rank) },
};
}
}