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
+7 -8
View File
@@ -1,4 +1,4 @@
import type { OccurringFeast } from '../calendar/types';
import type { DayWinner } from '../calendar/types';
import { isAtLeast } from '../calendar/commemorations';
export interface SplitAntiphon {
@@ -31,13 +31,12 @@ export function splitAntiphon(text: string): SplitAntiphon {
* said before the psalms (the full text is always said after, regardless
* of rank).
*
* Only asks whether the day's *winning* feast (not a merely-commemorated
* one) is Double-or-higher — a privileged Sunday with nothing occurring,
* or a commemorated low-rank saint, both correctly return false here. A
* Sunday being "privileged" doesn't by itself make this true; that's a
* Only asks whether the day's *winner* (not a merely-commemorated feast)
* is Double-or-higher — a privileged Sunday with nothing winning, or a
* commemorated low-rank saint, both correctly return false here. A Sunday
* being "privileged" doesn't by itself make this true; that's a
* `TemporalCategory` question, not a `FeastClass` one.
*/
export function isDoubleOrHigher(occurring: OccurringFeast[]): boolean {
const winner = occurring.find((feast) => !feast.commemorated);
return winner ? isAtLeast(winner.rank, 'duplex') : false;
export function isDoubleOrHigher(winner: DayWinner): boolean {
return winner.kind === 'sanctoral' && isAtLeast(winner.rank, 'duplex');
}
+3 -3
View File
@@ -1,4 +1,4 @@
import type { Season, OccurringFeast } from '../calendar/types';
import type { Season, DayWinner } from '../calendar/types';
import { resolveSeasonalPropersId } from './seasonal-propers';
import bySeasonData from '../data/hours/prime-chapter-responsory-by-season.yml';
import byFeastData from '../data/hours/prime-chapter-responsory-by-feast.yml';
@@ -7,6 +7,6 @@ const bySeason = bySeasonData as { perAnnum: string; bySeason: Record<string, st
const byFeast = byFeastData as { byFeastId: Record<string, string> };
/** Resolves the common-propers id for the chapter responsory's variable verse. */
export function getChapterResponsoryId(season: Season, occurring: OccurringFeast[]): string {
return resolveSeasonalPropersId(season, occurring, { ...bySeason, byFeastId: byFeast.byFeastId });
export function getChapterResponsoryId(season: Season, winner: DayWinner): string {
return resolveSeasonalPropersId(season, winner, { ...bySeason, byFeastId: byFeast.byFeastId });
}
+4 -4
View File
@@ -32,7 +32,7 @@ function resolvePart(part: HourPart, day: LiturgicalDay): ResolvedPart[] {
}
const body = resolveCommon(part.textRef.id);
const doxology = resolveCommon(
getHymnDoxologyId(day.season, day.occurring, 'compline-hymn-doxology-per-annum'),
getHymnDoxologyId(day.season, day.winner, 'compline-hymn-doxology-per-annum'),
);
return [{ kind: 'hymn', text: appendDoxology(body, doxology) }];
}
@@ -42,14 +42,14 @@ function resolvePart(part: HourPart, day: LiturgicalDay): ResolvedPart[] {
case 'prayer':
return [{ kind: part.kind, text: resolveCommon(part.textRef.id) }];
case 'preces':
if (part.omitOnDouble && isDoubleOrHigher(day.occurring)) {
if (part.omitOnDouble && isDoubleOrHigher(day.winner)) {
return [];
}
return [{ kind: 'preces', text: resolveCommon(part.textRef.id), label: part.label }];
case 'lesson':
return [{ kind: 'lesson', text: resolveCommon(part.textRef.id), label: part.label }];
case 'opening-versicle':
return [{ kind: 'versicle', text: resolveCommon(getOpeningVersicleId(day.season, day.occurring)) }];
return [{ kind: 'versicle', text: resolveCommon(getOpeningVersicleId(day.season, day.winner)) }];
case 'psalm':
return [
{
@@ -64,7 +64,7 @@ function resolvePart(part: HourPart, day: LiturgicalDay): ResolvedPart[] {
];
case 'nunc-dimittis': {
const { incipit, full } = splitNamedAntiphon(getCommonProper('nunc-dimittis-antiphon').text);
const opening = isDoubleOrHigher(day.occurring) ? full : incipit;
const opening = isDoubleOrHigher(day.winner) ? full : incipit;
return [
{ kind: 'canticle', canticleId: 'nunc-dimittis', text: resolveCommon('nunc-dimittis'), antiphon: opening },
{ kind: 'antiphon', text: full },
+3 -3
View File
@@ -1,4 +1,4 @@
import type { Season, OccurringFeast } from '../calendar/types';
import type { Season, DayWinner } from '../calendar/types';
import { resolveSeasonalPropersId } from './seasonal-propers';
import bySeasonData from '../data/hours/hymn-doxology-by-season.yml';
import byFeastData from '../data/hours/hymn-doxology-by-feast.yml';
@@ -12,8 +12,8 @@ const byFeast = byFeastData as { byFeastId: Record<string, string> };
* Officium's own Doxologies.txt table is hymn-agnostic), but the per-annum
* default is each hymn's own natural ending, so callers supply it.
*/
export function getHymnDoxologyId(season: Season, occurring: OccurringFeast[], perAnnumId: string): string {
return resolveSeasonalPropersId(season, occurring, {
export function getHymnDoxologyId(season: Season, winner: DayWinner, perAnnumId: string): string {
return resolveSeasonalPropersId(season, winner, {
perAnnum: perAnnumId,
bySeason: bySeason.bySeason,
byFeastId: byFeast.byFeastId,
+1 -1
View File
@@ -34,7 +34,7 @@ export function getMarianAntiphonId(day: LiturgicalDay): string {
if (isCandlemasToHolyWednesday(day.date)) {
return AVE_REGINA_CAELORUM_ID;
}
return resolveSeasonalPropersId(day.season, day.occurring, bySeason);
return resolveSeasonalPropersId(day.season, day.winner, bySeason);
}
const LABELS: Record<string, string> = {
+3 -3
View File
@@ -1,10 +1,10 @@
import type { Season, OccurringFeast } from '../calendar/types';
import type { Season, DayWinner } from '../calendar/types';
import { resolveSeasonalPropersId } from './seasonal-propers';
import bySeasonData from '../data/hours/opening-by-season.yml';
const bySeason = bySeasonData as { perAnnum: string; bySeason: Record<string, string> };
/** Resolves the common-propers id for the opening versicle's ending (Allelúja vs. Laus tibi). */
export function getOpeningVersicleId(season: Season, occurring: OccurringFeast[]): string {
return resolveSeasonalPropersId(season, occurring, bySeason);
export function getOpeningVersicleId(season: Season, winner: DayWinner): string {
return resolveSeasonalPropersId(season, winner, bySeason);
}
+7 -7
View File
@@ -21,7 +21,7 @@ function resolvePart(part: HourPart, date: string, day: LiturgicalDay): Resolved
switch (part.kind) {
case 'hymn': {
const body = resolveCommon(part.textRef.id);
const doxology = resolveCommon(getHymnDoxologyId(day.season, day.occurring, 'hymn-doxology-per-annum'));
const doxology = resolveCommon(getHymnDoxologyId(day.season, day.winner, 'hymn-doxology-per-annum'));
return [{ kind: 'hymn', text: appendDoxology(body, doxology) }];
}
case 'chapter':
@@ -30,14 +30,14 @@ function resolvePart(part: HourPart, date: string, day: LiturgicalDay): Resolved
case 'prayer':
return [{ kind: part.kind, text: resolveCommon(part.textRef.id) }];
case 'preces':
if (part.omitOnDouble && isDoubleOrHigher(day.occurring)) {
if (part.omitOnDouble && isDoubleOrHigher(day.winner)) {
return [];
}
return [{ kind: 'preces', text: resolveCommon(part.textRef.id), label: part.label }];
case 'lesson':
return [{ kind: 'lesson', text: resolveCommon(part.textRef.id), label: part.label }];
case 'opening-versicle':
return [{ kind: 'versicle', text: resolveCommon(getOpeningVersicleId(day.season, day.occurring)) }];
return [{ kind: 'versicle', text: resolveCommon(getOpeningVersicleId(day.season, day.winner)) }];
case 'creed':
// Real Divinum Officium's actual inclusion rule tangles together
// rank, commemorations, and version-specific rubrics in a way that
@@ -45,7 +45,7 @@ function resolvePart(part: HourPart, date: string, day: LiturgicalDay): Resolved
// Sunday and not a Double-or-higher feast. Octaves aren't modeled at
// all yet (milestone 4), so they can't suppress it either, same as
// isDoubleOrHigher's own limitation.
if (day.weekday !== 'sunday' || isDoubleOrHigher(day.occurring)) {
if (day.weekday !== 'sunday' || isDoubleOrHigher(day.winner)) {
return [];
}
return [{ kind: 'lesson', text: resolveCommon('athanasian-creed'), label: 'Athanasian Creed' }];
@@ -55,7 +55,7 @@ function resolvePart(part: HourPart, date: string, day: LiturgicalDay): Resolved
if (part.resolve === 'by-season') {
// Currently only the chapter responsory's verse uses this — see
// hours/chapter-responsory.ts. by-feast-rank doesn't apply to Prime.
return [{ kind: 'responsory', text: resolveCommon(getChapterResponsoryId(day.season, day.occurring)) }];
return [{ kind: 'responsory', text: resolveCommon(getChapterResponsoryId(day.season, day.winner)) }];
}
{
const psalmRefs = getPsalmsFor('prime', day.weekday);
@@ -63,7 +63,7 @@ function resolvePart(part: HourPart, date: string, day: LiturgicalDay): Resolved
// Full text on a Double-or-higher feast, otherwise just the incipit
// — see hours/antiphon.ts. The full repeat comes later, after the
// Creed (see 'closing-antiphon'), not tacked onto the last psalm.
const opening = isDoubleOrHigher(day.occurring) ? full : incipit;
const opening = isDoubleOrHigher(day.winner) ? full : incipit;
return psalmRefs.map((ref, i) => ({
kind: 'psalm' as const,
psalmNumber: ref.number,
@@ -86,7 +86,7 @@ function resolvePart(part: HourPart, date: string, day: LiturgicalDay): Resolved
case 'canticle':
return [{ kind: 'canticle', canticleId: part.canticleId, text: resolveCommon(part.textRef.id) }];
case 'by-day-kind': {
if (part.omitOnDouble && isDoubleOrHigher(day.occurring)) {
if (part.omitOnDouble && isDoubleOrHigher(day.winner)) {
return [];
}
const ref = isSundayOrFeast(day) ? part.sundayOrFeastRef : part.ferialRef;
+7 -12
View File
@@ -1,4 +1,4 @@
import type { Season, OccurringFeast } from '../calendar/types';
import type { Season, DayWinner } from '../calendar/types';
export interface SeasonalPropersTable {
perAnnum: string;
@@ -9,18 +9,13 @@ export interface SeasonalPropersTable {
/**
* Shared by everything that picks a common-propers id by season with a
* per-feast override (the chapter responsory's verse, the hymn doxology,
* and presumably more once milestone 4 lands) — feast overrides win over
* season, which wins over the "per annum" default. `occurring` is always
* [] until milestone 4, so today this always returns a season match or
* perAnnum.
* and presumably more once milestone 4 lands) — a feast override wins only
* when that feast is the day's actual *winner* (not merely commemorated),
* which wins over season, which wins over the "per annum" default.
*/
export function resolveSeasonalPropersId(
season: Season,
occurring: OccurringFeast[],
table: SeasonalPropersTable,
): string {
for (const feast of occurring) {
const override = table.byFeastId?.[feast.id];
export function resolveSeasonalPropersId(season: Season, winner: DayWinner, table: SeasonalPropersTable): string {
if (winner.kind === 'sanctoral') {
const override = table.byFeastId?.[winner.id];
if (override) {
return override;
}