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
+43 -11
View File
@@ -36,13 +36,28 @@ export type Weekday =
// third case shows up and the duplication starts to hurt.
export type Season = string;
// The old (pre-1955) rank scale, six levels, low to high. Deliberately a
// closed union rather than an open string like Season — the whole point of
// The old (pre-1955) rank scale, low to high. Deliberately a closed union
// rather than an open string like Season — the whole point of
// calendar/commemorations.ts's decideOccurrence is to compare two of these
// with explicit, readable rules, which only works if the set of values is
// fixed and known. See calendar/types.ts's TemporalCategory doc comment for
// the other half of that comparison.
export type FeastClass = 'simplex' | 'semiduplex' | 'duplex' | 'duplex-majus' | 'duplex-2-classis' | 'duplex-1-classis';
//
// `vigil` sits between `simplex` and `semiduplex` on purpose — it's the
// same strength as `simplex` for the "does this win against a Sunday"
// question (both lose and get transferred rather than fighting the day
// directly), but ranks strictly above `simplex` for the *separate*
// "two saints collide on the same landing day" comparison
// (calendar/collision.ts). One ordering serves both; see the design
// discussion in project history for why that isn't a coincidence.
export type FeastClass =
| 'simplex'
| 'vigil'
| 'semiduplex'
| 'duplex'
| 'duplex-majus'
| 'duplex-2-classis'
| 'duplex-1-classis';
// A day's own precedence class *before* any sanctoral feast is considered —
// i.e. what the temporal cycle alone says this day is entitled to. This is
@@ -57,17 +72,32 @@ export type FeastClass = 'simplex' | 'semiduplex' | 'duplex' | 'duplex-majus' |
// corrections.
export type TemporalCategory = 'ordinary-feria' | 'privileged-feria' | 'ordinary-sunday' | 'privileged-sunday';
export interface OccurringFeast {
export interface SanctoralIdentity {
id: string;
name: string;
rank: FeastClass;
commemorated: boolean;
// Set by calendar/vespers.ts's resolveEveningDay when this feast's First
// Vespers is being anticipated this evening (i.e. this OccurringFeast
// belongs to *tomorrow*, but is winning tonight's Vespers/Compline).
vespersFrom?: 'today' | 'firstVespersOfTomorrow';
}
export type DayWinner =
| { kind: 'temporal'; id: string }
| ({
kind: 'sanctoral';
// Set by calendar/vespers.ts's resolveEveningDay when this feast's
// First Vespers is being anticipated this evening (i.e. this feast
// belongs to *tomorrow*, but is winning tonight's Vespers/Compline).
vespersFrom?: 'firstVespersOfTomorrow';
} & SanctoralIdentity);
/**
* A day can have more than one of these at once (a transferred feast can
* displace a native saint who then also gets commemorated, alongside the
* Sunday whose own occurrence pushed the transfer in the first place) —
* hence a list, not a single flag. Extensible on purpose: a future
* `{ kind: 'octave'; id: string }` variant joins this union once octaves
* are modeled, without changing the shape callers already rely on.
*/
export type Commemoration = { kind: 'temporal'; id: string } | ({ kind: 'sanctoral' } & SanctoralIdentity);
export interface LiturgicalDay {
/** ISO date, e.g. "2026-08-09" */
date: string;
@@ -76,6 +106,8 @@ export interface LiturgicalDay {
season: Season;
/** This day's own precedence class, before any sanctoral feast wins or loses against it. */
temporalCategory: TemporalCategory;
/** The feast(s) actually occurring — real, via calendar/feasts.ts + calendar/commemorations.ts. */
occurring: OccurringFeast[];
/** Whichever office actually governs the day. */
winner: DayWinner;
/** Everything else commemorated alongside the winner — see the doc comment on Commemoration. */
commemorations: Commemoration[];
}