calendar: model octaves as a generic, data-driven mechanism
Deploy / deploy (push) Successful in 46s
Deploy / deploy (push) Successful in 46s
Adds calendar/octaves.ts: a lookback over the past week collecting every
octave (sanctoral or temporal) still active on a date, stacking multiple
at once (Christmas + St. Stephen + St. John + Holy Innocents all
commemorated together within the Christmas Octave). Declared via an
optional `octave` field on a saint's own record or a new small
TemporalFeastRecord (calendar/temporal-feasts.ts) for temporal ids like
Christmas/Pentecost that didn't have a metadata record before -- data-
driven per user design discussion, with `{ enabled: true }` alone using
sensible defaults (8 days, semiduplex threshold) so a minimal declaration
works without authored content.
Wired into resolveDay as a post-processing layer: doesn't change how a
single day's own precedence contest is decided, just adds commemorations
for active octaves and occasionally overrides the winner when the
occurring saint doesn't clear the strictest active octave's threshold.
Populated so far: St. Lawrence's own octave (the one that repeatedly cost
real saints their spot in August), the three Comites Christi octaves
(Stephen/John/Innocents -- Thomas of Canterbury deliberately excluded,
per discussion), and Pentecost's (duplex threshold, user-specified).
Pentecost's octave offsets are also removed from temporal-categories.yml's
privileged-feria-major classification, letting a real candidate reach the
new octave layer instead of being transferred away first -- with the
side effect that Pentecost's own Ember Saturday no longer forces a
transfer (a sub-threshold saint is now commemorated in place instead, see
tests/calendar/transfer.test.ts's updated case). Assumption, Nativity
BVM, Immaculate Conception, and All Saints' own octaves are not yet
populated with octave data -- deliberately deferred to a follow-up pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
// practice has its own precedence/commemoration rules for that too, not
|
||||
// modeled here. If a day has more than one candidate, calendar/index.ts
|
||||
// just picks the highest-ranked as the day's sole sanctoral contender.
|
||||
import type { FeastClass } from './types';
|
||||
import type { FeastClass, OctaveConfig } from './types';
|
||||
import sanctoralCalendarData from '../data/calendar/sanctoral-calendar.yml';
|
||||
|
||||
export interface SaintRecord {
|
||||
@@ -18,6 +18,9 @@ export interface SaintRecord {
|
||||
rank: FeastClass;
|
||||
common: string;
|
||||
propers: string | null;
|
||||
/** See calendar/types.ts's OctaveConfig doc comment. Absent for the vast
|
||||
* majority of saints — only ones with a real octave declare it. */
|
||||
octave?: OctaveConfig;
|
||||
}
|
||||
|
||||
const sanctoralCalendar = sanctoralCalendarData as { days: Record<string, string[]> };
|
||||
|
||||
+46
-1
@@ -3,9 +3,10 @@ import { weekdayOf } from './weekday';
|
||||
import { resolveSeason, resolveTemporalCategory } from './temporal';
|
||||
import { resolveTemporalId } from './temporal-id';
|
||||
import { getSanctoralCandidatesFor } from './feasts';
|
||||
import { decideOccurrence, type OccurrenceResult } from './commemorations';
|
||||
import { decideOccurrence, isAtLeast, type OccurrenceResult } from './commemorations';
|
||||
import { resolveCollision } from './collision';
|
||||
import { addDays } from './date-math';
|
||||
import { activeOctavesFor, strictestThreshold } from './octaves';
|
||||
|
||||
/**
|
||||
* A day's occurrence considered on its own — no awareness of what an
|
||||
@@ -99,9 +100,50 @@ export function resolveDay(isoDate: string): LiturgicalDay {
|
||||
winner = applyIncomingTransfer(tomorrow.result.transfer.candidate, temporalCategory, winner, commemorations);
|
||||
}
|
||||
|
||||
winner = applyOctaves(isoDate, winner, commemorations);
|
||||
|
||||
return { date: isoDate, weekday, season, temporalCategory, winner, commemorations };
|
||||
}
|
||||
|
||||
/**
|
||||
* Layered on top of everything above, not part of it: an octave doesn't
|
||||
* change how a single day's own precedence contest is decided, it just
|
||||
* (a) adds a commemoration for every octave still active on this date, and
|
||||
* (b) occasionally overrides the winner when the occurring saint is too
|
||||
* minor to clear the strictest active octave's threshold, in which case
|
||||
* the day reverts to its own temporal identity and the saint is
|
||||
* commemorated instead — same "demoted, not dropped" shape as every other
|
||||
* commemoration rule in this file.
|
||||
*/
|
||||
function applyOctaves(isoDate: string, winner: DayWinner, commemorations: Commemoration[]): DayWinner {
|
||||
const octaves = activeOctavesFor(isoDate);
|
||||
if (octaves.length === 0) {
|
||||
return winner;
|
||||
}
|
||||
|
||||
let resolvedWinner = winner;
|
||||
if (winner.kind === 'sanctoral' && !isAtLeast(winner.rank, strictestThreshold(octaves))) {
|
||||
const isOneOfTheseOctaves = octaves.some((o) => o.id === winner.id);
|
||||
if (!isOneOfTheseOctaves) {
|
||||
commemorations.push({ kind: 'sanctoral', id: winner.id, name: winner.name, rank: winner.rank });
|
||||
resolvedWinner = { kind: 'temporal', id: resolveTemporalId(isoDate) };
|
||||
}
|
||||
}
|
||||
|
||||
for (const octave of octaves) {
|
||||
const isSelf = resolvedWinner.kind === 'sanctoral' && resolvedWinner.id === octave.id;
|
||||
// An octave's own day-1, when nothing displaced it, already *is* that
|
||||
// feast (via the day's own temporal identity) — commemorating it
|
||||
// again alongside itself would be redundant.
|
||||
const isOwnStartDay = octave.dayNumber === 1 && resolvedWinner.kind === 'temporal';
|
||||
if (!isSelf && !isOwnStartDay) {
|
||||
commemorations.push({ kind: 'octave', id: octave.id, name: octave.name });
|
||||
}
|
||||
}
|
||||
|
||||
return resolvedWinner;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Sunday/feast-vs-ferial split that several hours' propers key off of
|
||||
* (Prime's capitulum and Preces, so far): a plain weekday with nothing else
|
||||
@@ -115,6 +157,8 @@ export function isSundayOrFeast(day: LiturgicalDay): boolean {
|
||||
export { compareFeastClass, isAtLeast, decideOccurrence } from './commemorations';
|
||||
export { resolveCollision } from './collision';
|
||||
export { resolveTemporalId } from './temporal-id';
|
||||
export { activeOctavesFor, strictestThreshold } from './octaves';
|
||||
export type { ActiveOctave } from './octaves';
|
||||
export type {
|
||||
LiturgicalDay,
|
||||
DayWinner,
|
||||
@@ -124,4 +168,5 @@ export type {
|
||||
Weekday,
|
||||
FeastClass,
|
||||
TemporalCategory,
|
||||
OctaveConfig,
|
||||
} from './types';
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// The "generic way to commemorate an octave" — a lookback over the past
|
||||
// week (a feast's own day plus up to 7 more) collecting every octave
|
||||
// still active on a given date, from *both* sanctoral saints
|
||||
// (calendar/feasts.ts) and temporal feasts (calendar/temporal-feasts.ts).
|
||||
// Deliberately a post-processing layer over calendar/index.ts's existing
|
||||
// occurrence/transfer pipeline, not a change to calendar/commemorations.ts
|
||||
// itself — an octave doesn't change *how* a single day's precedence
|
||||
// contest is decided, it just adds commemorations on top of whatever that
|
||||
// contest already produced, and occasionally overrides the winner when a
|
||||
// too-minor saint would otherwise have taken the day from it.
|
||||
import type { FeastClass, OctaveConfig } from './types';
|
||||
import { getSanctoralCandidatesFor, getSaintRecord } from './feasts';
|
||||
import { getTemporalFeastRecord, temporalFeastIdsStartingOn } from './temporal-feasts';
|
||||
import { addDays, daysBetween } from './date-math';
|
||||
import { compareFeastClass } from './commemorations';
|
||||
|
||||
export interface ActiveOctave {
|
||||
id: string;
|
||||
name: string;
|
||||
/** Rank threshold below which the occurring saint loses the day to this octave. */
|
||||
wins: FeastClass;
|
||||
/** 1 on the feast's own day, counting up from there. */
|
||||
dayNumber: number;
|
||||
}
|
||||
|
||||
const DEFAULT_DAYS = 8;
|
||||
const DEFAULT_WINS: FeastClass = 'semiduplex';
|
||||
/** How far back to look for an octave's own start date — must cover the
|
||||
* longest configured `days` a caller might use; 7 covers the standard
|
||||
* 8-day octave (day 1 = the start itself, day 8 = 7 days later). */
|
||||
const LOOKBACK_DAYS = 7;
|
||||
|
||||
function considerCandidate(
|
||||
active: ActiveOctave[],
|
||||
seen: Set<string>,
|
||||
isoDate: string,
|
||||
startDate: string,
|
||||
id: string,
|
||||
name: string,
|
||||
octave: OctaveConfig | undefined,
|
||||
): void {
|
||||
if (!octave?.enabled || seen.has(id)) {
|
||||
return;
|
||||
}
|
||||
const days = octave.days ?? DEFAULT_DAYS;
|
||||
const offset = daysBetween(startDate, isoDate);
|
||||
if (offset < 0 || offset >= days) {
|
||||
return;
|
||||
}
|
||||
seen.add(id);
|
||||
active.push({ id, name, wins: octave.wins ?? DEFAULT_WINS, dayNumber: offset + 1 });
|
||||
}
|
||||
|
||||
/** Every octave (sanctoral or temporal) whose window covers `isoDate`,
|
||||
* oldest-started first (so a stack like Christmas/Stephen/John/Innocents
|
||||
* reads in the order each one actually began, matching how they'd be
|
||||
* listed at Matins/Lauds/Vespers). */
|
||||
export function activeOctavesFor(isoDate: string): ActiveOctave[] {
|
||||
const active: ActiveOctave[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
for (let back = LOOKBACK_DAYS; back >= 0; back--) {
|
||||
const candidateDate = addDays(isoDate, -back);
|
||||
|
||||
for (const candidate of getSanctoralCandidatesFor(candidateDate)) {
|
||||
const record = getSaintRecord(candidate.id);
|
||||
if (record) {
|
||||
considerCandidate(active, seen, isoDate, candidateDate, record.id, record.name, record.octave);
|
||||
}
|
||||
}
|
||||
|
||||
for (const feastId of temporalFeastIdsStartingOn(candidateDate)) {
|
||||
const record = getTemporalFeastRecord(feastId);
|
||||
if (record) {
|
||||
considerCandidate(active, seen, isoDate, candidateDate, record.id, record.name, record.octave);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return active;
|
||||
}
|
||||
|
||||
/** The strictest (highest) `wins` threshold among a set of active octaves —
|
||||
* what an occurring saint needs to clear to keep the day against all of
|
||||
* them at once. */
|
||||
export function strictestThreshold(octaves: ActiveOctave[]): FeastClass {
|
||||
return octaves.reduce<FeastClass>(
|
||||
(max, o) => (compareFeastClass(o.wins, max) > 0 ? o.wins : max),
|
||||
octaves[0]?.wins ?? DEFAULT_WINS,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// The temporal-cycle sibling of calendar/feasts.ts's SaintRecord: a small
|
||||
// metadata record for a *temporal* id (Christmas, Pentecost, ...) that
|
||||
// needs to carry something beyond its collect text — so far, just whether
|
||||
// it has an octave (calendar/types.ts's OctaveConfig). Most temporal ids
|
||||
// don't need a record at all (they're just collect-text lookups via
|
||||
// propers/index.ts's getTemporalProper); this only exists for the ones
|
||||
// that do.
|
||||
import type { OctaveConfig } from './types';
|
||||
import { easterOffsetOf } from './temporal';
|
||||
|
||||
export interface TemporalFeastRecord {
|
||||
id: string;
|
||||
name: string;
|
||||
octave?: OctaveConfig;
|
||||
}
|
||||
|
||||
const temporalFeastModules = import.meta.glob<{ default: TemporalFeastRecord }>(
|
||||
'../data/calendar/temporal-feasts/*.yml',
|
||||
{ eager: true },
|
||||
);
|
||||
|
||||
const temporalFeastsById = new Map<string, TemporalFeastRecord>();
|
||||
for (const mod of Object.values(temporalFeastModules)) {
|
||||
temporalFeastsById.set(mod.default.id, mod.default);
|
||||
}
|
||||
|
||||
export function getTemporalFeastRecord(id: string): TemporalFeastRecord | undefined {
|
||||
return temporalFeastsById.get(id);
|
||||
}
|
||||
|
||||
/** Fixed-calendar-date starts (MM-DD -> temporal feast id). Only Christmas
|
||||
* so far; Epiphany/Candlemas would join here if they ever needed an
|
||||
* octave modeled too. */
|
||||
const FIXED_DATE_STARTS: [string, string][] = [['12-25', 'christmas-day']];
|
||||
|
||||
/** Easter-offset starts (offset -> temporal feast id). */
|
||||
const EASTER_OFFSET_STARTS: [number, string][] = [[49, 'pentecost-sunday']];
|
||||
|
||||
/** Which temporal feast(s), if any, have their own (day-1) octave start on this date. */
|
||||
export function temporalFeastIdsStartingOn(isoDate: string): string[] {
|
||||
const monthDay = isoDate.slice(5);
|
||||
const ids: string[] = [];
|
||||
for (const [md, id] of FIXED_DATE_STARTS) {
|
||||
if (md === monthDay) ids.push(id);
|
||||
}
|
||||
const offset = easterOffsetOf(isoDate);
|
||||
for (const [off, id] of EASTER_OFFSET_STARTS) {
|
||||
if (off === offset) ids.push(id);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
+36
-5
@@ -106,6 +106,34 @@ export interface SanctoralIdentity {
|
||||
rank: FeastClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attached to a saint's own record (calendar/feasts.ts's SaintRecord) or a
|
||||
* temporal feast's (calendar/temporal-feasts.ts's TemporalFeastRecord) to
|
||||
* declare that it carries an octave — commemorated daily for `days` days
|
||||
* after its own feast, layered on top of whatever normally wins each of
|
||||
* those days. `enabled: false` (or the field simply absent) means no
|
||||
* octave; `{ enabled: true }` alone is valid and uses every default below,
|
||||
* satisfying the "turned on but no octave data authored yet" case —
|
||||
* calendar/octaves.ts is the "generic way to commemorate an octave" that
|
||||
* makes that minimal declaration meaningful on its own.
|
||||
*/
|
||||
export interface OctaveConfig {
|
||||
enabled: boolean;
|
||||
/** Length of the octave in days, inclusive of the feast's own day. Default 8. */
|
||||
days?: number;
|
||||
/** Rank threshold: an occurring saint at this rank or higher keeps the
|
||||
* day for itself (the octave is merely commemorated back); below it, the
|
||||
* octave wins the day instead and the saint is commemorated. Default
|
||||
* 'semiduplex' — i.e. only a Simplex loses to the octave — matching
|
||||
* every octave checked so far except Pentecost's (see
|
||||
* data/calendar/temporal-feasts/pentecost-sunday.yml), which is
|
||||
* stricter (`duplex`). */
|
||||
wins?: FeastClass;
|
||||
/** Matins reading proper id, if one has been sourced. Absent by default
|
||||
* — most octaves checked so far have none. */
|
||||
readingId?: string;
|
||||
}
|
||||
|
||||
export type DayWinner =
|
||||
| { kind: 'temporal'; id: string }
|
||||
| ({
|
||||
@@ -119,12 +147,15 @@ export type DayWinner =
|
||||
/**
|
||||
* 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.
|
||||
* Sunday whose own occurrence pushed the transfer in the first place, or —
|
||||
* since octaves were modeled — several overlapping octaves stacking on one
|
||||
* date, e.g. Christmas + St. Stephen + St. John all commemorated together
|
||||
* within the Christmas Octave) — hence a list, not a single flag.
|
||||
*/
|
||||
export type Commemoration = { kind: 'temporal'; id: string } | ({ kind: 'sanctoral' } & SanctoralIdentity);
|
||||
export type Commemoration =
|
||||
| { kind: 'temporal'; id: string }
|
||||
| ({ kind: 'sanctoral' } & SanctoralIdentity)
|
||||
| { kind: 'octave'; id: string; name: string };
|
||||
|
||||
export interface LiturgicalDay {
|
||||
/** ISO date, e.g. "2026-08-09" */
|
||||
|
||||
Reference in New Issue
Block a user