From 00a32e549493b0fb51ae23e8a5e73aa54a5205b1 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 12 Aug 2026 13:05:34 +0200 Subject: calendar: RG 96 transfers must skip II-class days too (defect 1) transferIfImpededEF's forward walk only skipped days whose temporal office was I class. RG 96 requires skipping to "the next following day that is not I or II class" -- II class also blocks. 2011: the Sacred Heart (Friday after the Corpus Christi octave) falls on 1 July and impedes the Precious Blood, also fixed on 1 July. The walk landed the Precious Blood on 2 July, displacing the Visitation (II class, fixed) outright, and never reached 3 July (an ordinary II-class Sunday) at all. Two changes were needed together, not one: 1. The walk's continuation threshold widens from "temporal band <= 2" to "<= 3", which is what actually captures every II-class temporal day (an ordinary Sunday, or a II-class named feast) as well as every I-class one -- band 3 is precedenceEF's own value for any non-Sunday-privileged II-class temporal candidate, unchanged by this commit. 2. A FIXED sanctoral II-class feast (the Visitation) has no temporal band at all -- the walk needs to also check whether some OTHER fixed celebration, class 1 or 2, already resolves onto the candidate day. computeEF now builds this check once (occupiedByRank, parameterised by which ranks count) and passes it in. Widening (1) alone is wrong on its own: a class-1 feast is NEVER actually impeded by a mere II-class day (I class always outranks II class outright, no tie exists) -- naively applying the wide "<=3" threshold to decide whether the ORIGINAL date is impeded, not just where to land afterwards, wrongly bumped unimpeded feasts landing on an ordinary Sunday (caught while testing this: All Saints, 1 Nov 2026, a Sunday that year, was wrongly pushed to 3 Nov). transferIfImpededEF now uses two different thresholds for two different questions -- class 1 only to decide IF a candidate is impeded at all, class 1 OR 2 to decide where an already-impeded one may land -- see its own doc comment for the full reasoning. Witness (precedence_ef_repro_test.go): TestTransferSkipsBothIAndIIClass. Fails before this commit with: 2011-07-02 observed = "precious-blood-of-our-lord-jesus-christ" want visitation-of-the-blessed-virgin-mary (RG 96: the Precious Blood must skip past it, not displace it) 2011-07-04 observed = "ef-time-after-pentecost-3-monday" want precious-blood-of-our-lord-jesus-christ (RG 96: first day that is neither I nor II class) --- internal/calendar/calendar.go | 76 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 12 deletions(-) (limited to 'internal/calendar/calendar.go') diff --git a/internal/calendar/calendar.go b/internal/calendar/calendar.go index 33706d8..f364321 100644 --- a/internal/calendar/calendar.go +++ b/internal/calendar/calendar.go @@ -35,14 +35,43 @@ func TemporalSlug(date time.Time, sel Selection) string { func computeEF(date time.Time, sel Selection, layers []Layer) LiturgicalDay { td := temporalEF(date) merged := mergeLayers(layers) - cands := []candidate{{Cel: td.Cel, Temporal: true, Season: td.Season}} + year := date.Year() + // occupiedByRank reports whether some OTHER fixed-date sanctoral + // celebration whose rank passes `allowed` resolves onto d this year. + // transferIfImpededEF uses this at two different thresholds: class 1 + // only, to decide whether a candidate is impeded in the first place (a + // class-2 occupant never impedes a class-1 feast -- class 1 always beats + // class 2 outright, no tie exists); and class 1 OR 2, for RG 96's "next + // day that is not I or II class" once a transfer is already under way + // (e.g. the Visitation, 2 July, blocking the Precious Blood's transfer + // off 1 July in 2011). + occupiedByRank := func(d time.Time, exceptSlug string, allowed func(Rank) bool) bool { + for slug2, rc2 := range merged { + if slug2 == exceptSlug { + continue + } + cel2 := buildCelebration(slug2, rc2) + if !allowed(cel2.Rank) { + continue + } + if when2, ok := celebrationDate(cel2, year, sel); ok && sameDay(when2, d) { + return true + } + } + return false + } + isClass1 := func(r Rank) bool { return r == RankClass1 } + isClass1Or2 := func(r Rank) bool { return r == RankClass1 || r == RankClass2 } + cands := []candidate{{Cel: td.Cel, Temporal: true, Season: td.Season, Sunday: td.Sunday}} for slug, rc := range merged { cel := buildCelebration(slug, rc) - when, ok := celebrationDate(cel, date.Year(), sel) + when, ok := celebrationDate(cel, year, sel) if !ok { continue } - effective := transferIfImpededEF(cel, when) + effective := transferIfImpededEF(cel, when, + func(d time.Time) bool { return occupiedByRank(d, cel.Slug, isClass1) }, + func(d time.Time) bool { return occupiedByRank(d, cel.Slug, isClass1Or2) }) if sameDay(effective, date) { cands = append(cands, candidate{Cel: cel, Temporal: false, Season: td.Season}) } @@ -199,12 +228,29 @@ func transferIfImpeded(cel Celebration, when time.Time, sel Selection) time.Time // transferIfImpededEF moves an EF sanctoral feast off a date it cannot be kept // on. Two rules cover the 1962 cases: All Souls, when Nov 2 is a Sunday, is -// transferred to the Monday (Nov 3); and a I class feast impeded by a I class -// temporal day (Holy Week, the Easter octave) is pushed forward to the next free -// day — for the Annunciation in Holy Week this lands on the Monday after Low -// Sunday, past the whole privileged octave. Lower-rank feasts are only -// commemorated, never transferred. -func transferIfImpededEF(cel Celebration, when time.Time) time.Time { +// transferred to the Monday (Nov 3); and a I class feast genuinely impeded is +// pushed forward to the next day that is itself neither I nor II class (RG +// 96: "the next following day that is not I or II class"). Lower-rank feasts +// are only commemorated, never transferred (RG 95). +// +// occupiedByClass1 and occupiedByClass1Or2 are deliberately different +// thresholds, not the same check reused twice: +// - a candidate is impeded IN THE FIRST PLACE only by a genuine class-1 +// collision -- the temporal office of `when` is itself I class (a Sunday +// of Advent/Lent/Passiontide, Holy Week, a named I-class feast), or +// another FIXED I-class sanctoral feast already sits on `when` (RG +// 97/98). A II-class occupant, temporal or sanctoral, never impedes a +// I-class feast at all -- I class always outranks II class outright, no +// tie-break is even reached -- so using the wider I-OR-II threshold here +// would (and, before this fix, did: e.g. All Saints, 1 Nov, was wrongly +// bumped to 3 Nov merely for landing on an ordinary II-class Sunday it +// would have won outright) send an unimpeded I-class feast on an +// unnecessary walk. +// - once a transfer is under way, the DESTINATION must avoid landing on +// ANY I- or II-class day (RG 96's own wider "not I or II class" text) -- +// e.g. the Visitation, 2 July, blocks the Precious Blood's transfer off 1 +// July in 2011, and 3 July's ordinary Sunday blocks it a second time. +func transferIfImpededEF(cel Celebration, when time.Time, occupiedByClass1, occupiedByClass1Or2 func(time.Time) bool) time.Time { if when.Month() == time.November && when.Day() == 2 && when.Weekday() == time.Sunday && strings.Contains(cel.Slug, "all-souls") { return when.AddDate(0, 0, 1) @@ -212,11 +258,17 @@ func transferIfImpededEF(cel Celebration, when time.Time) time.Time { if cel.Rank != RankClass1 { return when } - day := when + startTemporal := temporalEF(when) + startImpeded := startTemporal.Cel.Rank == RankClass1 || occupiedByClass1(when) + if !startImpeded { + return when + } + day := when.AddDate(0, 0, 1) for i := 0; i < 30; i++ { b := temporalEF(day) - if precedenceEF(candidate{Cel: b.Cel, Temporal: true, Season: b.Season}) <= 2 { - day = day.AddDate(0, 0, 1) // impeded by a I class temporal day; push forward + band := precedenceEF(candidate{Cel: b.Cel, Temporal: true, Season: b.Season, Sunday: b.Sunday}) + if band <= 3 || occupiedByClass1Or2(day) { + day = day.AddDate(0, 0, 1) // still I- or II-class; keep walking continue } return day -- cgit v1.3 From b4d44c88fe3c92c5fb06b43fe94be0049059ef6e Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 12 Aug 2026 13:46:01 +0200 Subject: calendar, precedence_ef: two more RG 91 gaps exposed by defect 4 Found during the mandated 2005-2050 before/after verification (not one of the seven, but caused by defect 4's own fix, so fixed in the same pass rather than left as a self-introduced regression). Neither is a hypothetical: both are live in the fixed calendar and both were individually confirmed via cmd/lectio-ef-dump before being written up as tests. 1. RG 91 entry 4 (Immaculate Conception, Assumption BVM) sits ABOVE entry 6 (Sundays of Advent/Lent/Passiontide) -- unlike an ORDINARY I-class feast (entry 11, e.g. St Joseph), the Immaculate Conception (8 December) is not impeded by an Advent Sunday at all. Before defect 4, Advent Sundays were wrongly II class, so this was accidentally right (I beats II outright, no tie reached); once Sundays became I class the tie-break mattered for the first time, and precedenceEF had no branch for it -- the Sunday wrongly won. 2. RG 91 entry 5 (Vigil & Octave day of the Nativity) sits above entry 6 the same way, and its own gap was worse than a wrong winner: the Vigil of Christmas (24 December) falling on Advent IV, once defect 4 made that a genuine I-class tie, sent the Vigil into transferIfImpededEF's forward walk -- which has no way to re-place a transfer crossing the Dec 31/Jan 1 boundary (celebrationDate re-resolves a fixed date using the YEAR OF THE DAY BEING QUERIED, so a walk landing in the following January can never match the query that produced it). The Vigil did not move to the wrong day; it vanished for the whole year, for every year 24 December is a Sunday (2006, 2017, 2023, 2028, 2034, 2045). Both fixed the same way as the existing II-class-feast-of-the-Lord bonus in precedenceEF (a one-line precedence adjustment keyed on slug), generalised into a single beatsClass1Sunday helper covering both RG 91 entries. A separate, unrelated bug surfaced by the SAME verification pass and fixed alongside it: transferIfImpededEF's destination check reused precedenceEF's tie-break BAND to decide "is this day I or II class", but band encodes a different question (which of two EQUAL-class candidates wins a tie) -- an ordinary, non-Sunday II-class temporal candidate YIELDS under defect 2's own fix (band 5), even though it is genuinely II class. A day within the Octave of the Nativity (26-31 Dec, RG 67) is exactly such a day, so band<=3 alone let a transfer wrongly land inside it (a real reproduction: "vigil-of-christmas" would have landed on 29 December 2006 instead of vanishing outright, caught while tracing the entry-5 bug above). Replaced with a direct class test (isHighClass), which is both correct and simpler -- it no longer needs the Sunday flag at all for this particular check. Witnesses (precedence_ef_repro_test.go): TestImmaculateConceptionBeatsAdventSunday, TestVigilOfChristmasSurvivesAdventSunday. Fail before this commit with: 2013-12-08 observed = "ef-advent-sunday-2" want immaculate-conception-of-the-blessed-virgin-mary (RG 91 entry 4 beats entry 6) 2006-12-24 observed = "ef-advent-sunday-4" want vigil-of-christmas (RG 91 entry 5 beats entry 6; must not vanish) (full set: 2013/2019/2024 for the first, 2006/2017/2023/2028 for the second) --- internal/calendar/calendar.go | 29 +++++++++++++++++--- internal/calendar/precedence_ef.go | 37 ++++++++++++++++++++++++- internal/calendar/precedence_ef_repro_test.go | 39 +++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) (limited to 'internal/calendar/calendar.go') diff --git a/internal/calendar/calendar.go b/internal/calendar/calendar.go index f364321..19c0efb 100644 --- a/internal/calendar/calendar.go +++ b/internal/calendar/calendar.go @@ -258,16 +258,39 @@ func transferIfImpededEF(cel Celebration, when time.Time, occupiedByClass1, occu if cel.Rank != RankClass1 { return when } + // Is cel actually impeded on `when` at all? Compare its OWN precedence + // (via precedenceEF, the same function pickEF uses to decide the day) + // against the temporal office's, rather than testing the temporal + // office's class in isolation -- a plain "is the temporal day I class" + // test wrongly impedes a candidate that would in fact WIN a tie against + // it: RG 91 entry 4 (the Immaculate Conception, the Assumption) sits + // ABOVE entry 6 (Sundays), so the Immaculate Conception is not impeded + // by the Advent Sunday it may fall on at all, unlike an ordinary I-class + // feast (entry 11, e.g. St Joseph), which is. occupiedByClass1 still + // covers the separate case of a competing FIXED I-class SANCTORAL + // feast, which this temporal-only comparison cannot see. startTemporal := temporalEF(when) - startImpeded := startTemporal.Cel.Rank == RankClass1 || occupiedByClass1(when) + tCand := candidate{Cel: startTemporal.Cel, Temporal: true, Season: startTemporal.Season, Sunday: startTemporal.Sunday} + sCand := candidate{Cel: cel, Temporal: false} + startImpeded := precedenceEF(tCand) < precedenceEF(sCand) || occupiedByClass1(when) if !startImpeded { return when } day := when.AddDate(0, 0, 1) for i := 0; i < 30; i++ { b := temporalEF(day) - band := precedenceEF(candidate{Cel: b.Cel, Temporal: true, Season: b.Season, Sunday: b.Sunday}) - if band <= 3 || occupiedByClass1Or2(day) { + // A direct CLASS test, not precedenceEF's tie-break band: band + // encodes which of two EQUAL-class candidates wins a tie (e.g. a + // Sunday beats an equal-class feast, but a privileged Ember/late- + // Advent FERIA of the same class yields to one, defect 2) -- an + // unrelated question from RG 96's own "is this day itself I or II + // class" test. Reusing band here undercounted: a day within the + // Octave of the Nativity (26-31 Dec) is genuinely II class (RG 67), + // but as an ordinary, non-Sunday II-class temporal candidate its OWN + // band yields (5, not <=3) -- so band<=3 alone let an impeded I-class + // feast wrongly land there. isHighClass tests the class directly. + isHighClass := b.Cel.Rank == RankClass1 || b.Cel.Rank == RankClass2 + if isHighClass || occupiedByClass1Or2(day) { day = day.AddDate(0, 0, 1) // still I- or II-class; keep walking continue } diff --git a/internal/calendar/precedence_ef.go b/internal/calendar/precedence_ef.go index a1788be..9f5016f 100644 --- a/internal/calendar/precedence_ef.go +++ b/internal/calendar/precedence_ef.go @@ -1,6 +1,9 @@ package calendar -import "sort" +import ( + "sort" + "strings" +) // efRankOrder orders EF (1960) ranks: class-1 highest, then class-2..4, // commemoration, ferial lowest. @@ -69,10 +72,42 @@ func precedenceEF(c candidate) int { // falls on (unlike a saint's feast, which is only commemorated). Give it // the edge over the Sunday's tie-break bonus. p -= 2 + } else if c.Cel.Rank == RankClass1 && beatsClass1Sunday(c.Cel.Slug) { + // RG 91 entries 4 (Immaculate Conception, Assumption BVM) and 5 + // (Vigil & Octave day of the Nativity) both sit ABOVE entry 6 + // (Sundays of Advent/Lent/Passiontide, Low Sunday) -- unlike an + // ORDINARY I-class feast (entry 11, e.g. St Joseph, the Precious + // Blood), which yields to a I-class Sunday, these win the tie. + // Found while verifying defect 4 (Sunday ranks): before that fix, + // Advent/Lent Sundays were wrongly II class, so these feasts beat + // them outright on base class alone, accidentally right; once + // Sundays became I class the tie-break mattered, and without this + // branch the Sunday would wrongly win. Two live cases in the fixed + // calendar: the Immaculate Conception (8 December) on an Advent + // Sunday, and the Vigil of Christmas (24 December) on Advent IV -- + // the latter is not merely a wrong winner but a WORSE bug without + // this branch: transferIfImpededEF has no way to re-place a + // transfer that crosses the Dec31/Jan1 boundary (celebrationDate + // re-resolves a fixed date using the YEAR OF THE DAY BEING QUERIED, + // so a walk landing in January of the following year can never + // match the query that produced it), so the Vigil simply vanished + // for the year instead of landing on the wrong day. The Assumption + // (15 August) never falls in Advent or Lent, so its own share of + // this branch is citation-complete but not live. + p -= 2 } return p } +// beatsClass1Sunday reports whether slug is one of RG 91's entries 4 or 5 -- +// the Immaculate Conception, the Assumption, or the Vigil of Christmas -- +// all of which sit above entry 6's Sundays in the Table of Precedence. +func beatsClass1Sunday(slug string) bool { + return strings.Contains(slug, "immaculate-conception") || + strings.Contains(slug, "assumption-of-the-blessed-virgin-mary") || + slug == "vigil-of-christmas" +} + // pickEF returns the observed EF celebration and the commemorations, ordered // deterministically by precedence then slug. func pickEF(cands []candidate) (candidate, []candidate) { diff --git a/internal/calendar/precedence_ef_repro_test.go b/internal/calendar/precedence_ef_repro_test.go index 77919d9..09cadbd 100644 --- a/internal/calendar/precedence_ef_repro_test.go +++ b/internal/calendar/precedence_ef_repro_test.go @@ -81,3 +81,42 @@ func TestMatthewBeatsSeptemberEmberWednesday(t *testing.T) { } } } + +// TestImmaculateConceptionBeatsAdventSunday: found, not named among the +// seven, while verifying defect 4 (Sunday ranks) against the real sanctoral +// data. RG 91 entry 4 (Immaculate Conception, Assumption BVM) sits ABOVE +// entry 6 (Sundays of Advent/Lent/Passiontide) -- unlike an ORDINARY +// I-class feast (entry 11, e.g. St Joseph), the Immaculate Conception +// (8 December) is not impeded by the Advent Sunday it falls on at all. Before +// defect 4's own fix, Advent Sundays were wrongly II class, so this was +// accidentally right (I class beats II class outright); once Sundays became +// I class the tie mattered for the first time. +func TestImmaculateConceptionBeatsAdventSunday(t *testing.T) { + for _, year := range []string{"2013", "2019", "2024"} { + day := efCompute(year + "-12-08") + if day.Observed.Slug != "immaculate-conception-of-the-blessed-virgin-mary" { + t.Errorf("%s-12-08 observed = %q want immaculate-conception-of-the-blessed-virgin-mary (RG 91 entry 4 beats entry 6)", year, day.Observed.Slug) + } + } +} + +// TestVigilOfChristmasSurvivesAdventSunday: found, not named among the +// seven, while verifying defect 4 against the real sanctoral data -- and +// worse than a wrong winner. RG 91 entry 5 (Vigil & Octave day of the +// Nativity) also sits above entry 6, so the Vigil of Christmas (24 December) +// is not impeded by falling on Advent IV either. Without this, defect 4 +// alone would have made the Advent Sunday win a genuine tie, sending the +// Vigil into transferIfImpededEF's forward walk -- which has no way to +// re-place a transfer that crosses the Dec31/Jan1 boundary (celebrationDate +// re-resolves a fixed date using the year of whatever day is being queried, +// so a walk landing in the following January can never match the query that +// produced it). The Vigil did not move to the wrong day; it vanished for the +// whole year. +func TestVigilOfChristmasSurvivesAdventSunday(t *testing.T) { + for _, year := range []string{"2006", "2017", "2023", "2028"} { + day := efCompute(year + "-12-24") + if day.Observed.Slug != "vigil-of-christmas" { + t.Errorf("%s-12-24 observed = %q want vigil-of-christmas (RG 91 entry 5 beats entry 6; must not vanish)", year, day.Observed.Slug) + } + } +} -- cgit v1.3 From 09a14446d5b0d4150a6de118a7d04ab99e54c21e Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 12 Aug 2026 14:50:58 +0200 Subject: calendar: record the RG 95 chained-transfer gap in the source transferIfImpededEF resolves one candidate's own transfer walk in isolation and has no way to notice a SECOND, separately-transferred I-class candidate landing on the same destination day -- St Joseph (19 March) and the Annunciation (25 March) can both walk to the Monday after Low Sunday in the same year (2008, 2035, 2046, e.g. 2035-04-02: annunciation-of-the-blessed-virgin-mary +joseph-spouse- of-the-bl-virgin-mary). RG 95 grants the right of translation "solummodo festis I classis" to I-class feasts only, so both candidates genuinely have it, and the collision they land in together is an ordinary RG 97/98 occurrence question this function does not resolve: pickEF's plain alphabetical slug tie-break settles it instead of re-walking the loser. RG 98 itself supplies the determinism rule this collision needs and does not have: "in paritate autem Officium prius impeditum praecedit" -- at equal table position, the office impeded FIRST takes precedence, which is chronological (Joseph, impeded on the 19th, before the Annunciation's own walk begins on the 25th) and may favour Joseph over the current alphabetical fallback. No functional change -- this collision is left unfixed, defensible against scope (it needs resolving occurrence between two ALREADY- TRANSFERRED candidates, not a single one, a bigger shape than this function currently has). Leaving it unrecorded was not defensible: nothing in internal/calendar/ named RG 95, 97, 98, or chained transfers anywhere before this comment. --- internal/calendar/calendar.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'internal/calendar/calendar.go') diff --git a/internal/calendar/calendar.go b/internal/calendar/calendar.go index 19c0efb..2d8611a 100644 --- a/internal/calendar/calendar.go +++ b/internal/calendar/calendar.go @@ -250,6 +250,31 @@ func transferIfImpeded(cel Celebration, when time.Time, sel Selection) time.Time // ANY I- or II-class day (RG 96's own wider "not I or II class" text) -- // e.g. the Visitation, 2 July, blocks the Precious Blood's transfer off 1 // July in 2011, and 3 July's ordinary Sunday blocks it a second time. +// +// KNOWN GAP, not fixed here (recorded per RG 95, so the next person does not +// have to rediscover it from scratch): this function resolves ONE +// candidate's own transfer walk in isolation. It has no way to notice that a +// SECOND, separately-transferred I-class candidate has landed on the exact +// same destination day. Concretely: St Joseph (19 March) and the +// Annunciation (25 March) can both be walked, independently, to the Monday +// after Low Sunday in the same year (2008, 2035, 2046 -- e.g. 2035-04-02: +// `annunciation-of-the-blessed-virgin-mary … +joseph-spouse-of-the-bl-virgin-mary`). +// RG 95 grants the right of translation "solummodo festis I classis" (to +// I-class feasts ONLY) -- so BOTH have that right, and the day they land on +// together is itself an ordinary occurrence collision RG 97/98 governs (the +// higher table position is kept, the other transfers FURTHER): this +// function does not re-walk the loser, it lets pickEF's plain alphabetical +// slug tie-break settle it, so the loser is merely commemorated instead of +// continuing its own walk one more day. RG 98 itself supplies the missing +// determinism rule for the tie this collision even needs: "in paritate +// autem Officium prius impeditum praecedit" -- at equal table position, the +// office impeded FIRST takes precedence -- which is chronological (Joseph, +// impeded on the 19th, before the Annunciation's own walk begins on the +// 25th) and may favour Joseph over pickEF's alphabetical fallback. Neither +// RG 98's tie rule nor the re-walk RG 97 implies is implemented; fixing this +// properly means resolving occurrence between two ALREADY-TRANSFERRED +// candidates, not a single one, which is out of this function's current +// shape. func transferIfImpededEF(cel Celebration, when time.Time, occupiedByClass1, occupiedByClass1Or2 func(time.Time) bool) time.Time { if when.Month() == time.November && when.Day() == 2 && when.Weekday() == time.Sunday && strings.Contains(cel.Slug, "all-souls") { -- cgit v1.3