calendar: occurrence engine v2 — real rank thresholds, transfers, collisions
Deploy / deploy (push) Successful in 39s
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:
+9
-17
@@ -8,7 +8,7 @@
|
||||
// Same reconstruction caveat as commemorations.ts/temporal-categories.yml:
|
||||
// best-effort, not sourced from a primary text for this era, expect
|
||||
// corrections.
|
||||
import type { LiturgicalDay, OccurringFeast } from './types';
|
||||
import type { LiturgicalDay } from './types';
|
||||
import { resolveDay } from './index';
|
||||
import { addDays } from './date-math';
|
||||
import { easterOffsetOf } from './temporal';
|
||||
@@ -32,17 +32,12 @@ function isMajorFixedFeastOfTheLord(isoDate: string): boolean {
|
||||
return offset === 0 || offset === 39 || offset === 60 || offset === 68; // Easter, Ascension, Corpus Christi, Sacred Heart
|
||||
}
|
||||
|
||||
function winningFeast(day: LiturgicalDay): OccurringFeast | undefined {
|
||||
return day.occurring.find((feast) => !feast.commemorated);
|
||||
}
|
||||
|
||||
/** Does this day's evening claim First Vespers at all (for the day *after* it)? */
|
||||
function hasFirstVespers(day: LiturgicalDay): boolean {
|
||||
if (day.weekday === 'sunday' || isMajorFixedFeastOfTheLord(day.date)) {
|
||||
return true;
|
||||
}
|
||||
const winner = winningFeast(day);
|
||||
return winner ? isAtLeast(winner.rank, 'duplex-majus') : false;
|
||||
return day.winner.kind === 'sanctoral' && isAtLeast(day.winner.rank, 'duplex-majus');
|
||||
}
|
||||
|
||||
/** Does this day keep its own Second Vespers regardless of what tomorrow is? */
|
||||
@@ -50,17 +45,14 @@ function keepsOwnSecondVespers(day: LiturgicalDay): boolean {
|
||||
if (day.weekday === 'sunday' || day.temporalCategory === 'privileged-feria' || isMajorFixedFeastOfTheLord(day.date)) {
|
||||
return true;
|
||||
}
|
||||
const winner = winningFeast(day);
|
||||
return winner ? isAtLeast(winner.rank, 'duplex-2-classis') : false;
|
||||
return day.winner.kind === 'sanctoral' && isAtLeast(day.winner.rank, 'duplex-2-classis');
|
||||
}
|
||||
|
||||
function anticipated(tomorrow: LiturgicalDay): LiturgicalDay {
|
||||
return {
|
||||
...tomorrow,
|
||||
occurring: tomorrow.occurring.map((feast) =>
|
||||
feast.commemorated ? feast : { ...feast, vespersFrom: 'firstVespersOfTomorrow' },
|
||||
),
|
||||
};
|
||||
if (tomorrow.winner.kind === 'sanctoral') {
|
||||
return { ...tomorrow, winner: { ...tomorrow.winner, vespersFrom: 'firstVespersOfTomorrow' } };
|
||||
}
|
||||
return tomorrow;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,10 +60,10 @@ function anticipated(tomorrow: LiturgicalDay): LiturgicalDay {
|
||||
* Returns `resolveDay(isoDate)` unchanged unless tomorrow has First
|
||||
* Vespers *and* today doesn't keep its own Second Vespers regardless — in
|
||||
* which case returns tomorrow's `LiturgicalDay`, with `vespersFrom:
|
||||
* 'firstVespersOfTomorrow'` set on its winning feast (if any) so callers
|
||||
* 'firstVespersOfTomorrow'` set on its winner (if sanctoral) so callers
|
||||
* can tell the difference from an ordinary day.
|
||||
*
|
||||
* One deliberate exception to that ordering: a day on
|
||||
* One deliberate absolute exception, caught by a failing test: a day on
|
||||
* `isMajorFixedFeastOfTheLord`'s list always wins tomorrow's Vespers,
|
||||
* *before* checking whether today would otherwise keep its own — Easter
|
||||
* displaces even Holy Saturday's privileged-feria status (the classic
|
||||
|
||||
Reference in New Issue
Block a user