From 53e0639612a348ddc66e33952d913c5257fe2ba8 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 11 Aug 2026 14:02:35 +0200 Subject: rite(ef): pin down floor_div and week/sunday_slug agreement Task 12 review: add a permanent regression test for floor_div's negative branch (Ash Wednesday, 4 days before the Lent I origin -- the only date in the system where it fires), and stop sunday_slug from independently recomputing the Pentecost-relative week number that week already computes. A cross-check test pins the two together before the refactor and continues to guard against future duplication. --- lib/rites/rite_ef/temporal_ef.ml | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'lib/rites/rite_ef/temporal_ef.ml') diff --git a/lib/rites/rite_ef/temporal_ef.ml b/lib/rites/rite_ef/temporal_ef.ml index 9e8bcc4..6786cd2 100644 --- a/lib/rites/rite_ef/temporal_ef.ml +++ b/lib/rites/rite_ef/temporal_ef.ml @@ -165,20 +165,24 @@ let sunday_slug d = Some "ef-holy-name-sunday" else None | Time_after_pentecost -> ( - let easter = Computus.gregorian_easter y in - let pentecost = Date.add_days easter 49 in - let last_sunday = Date.add_days (advent_start y) (-7) in - let n = days_between pentecost d / 7 in - if same d last_sunday then - (* The last Sunday before Advent always keeps the 24th (Last) Mass. *) - Some "ef-time-after-pentecost-sunday-24" - else if n > 23 then - (* Surplus Sundays resume the Sundays after Epiphany that Septuagesima - cut short -- the highest-numbered ones, so the 6th sits just before - the Last. *) - let total = days_between pentecost last_sunday / 7 in - Some (Printf.sprintf "ef-time-after-epiphany-sunday-%d" (n - total + 7)) - else Some (Printf.sprintf "ef-time-after-pentecost-sunday-%d" n)) + (* Reuse [week] rather than recomputing the Pentecost-relative week + number locally, so the two can never drift apart (see + test_week_sunday_slug_agree). Only the last Sunday and the resumed + tail are genuinely special. *) + match week d with + | None -> None + | Some n -> + let last_sunday = Date.add_days (advent_start y) (-7) in + if same d last_sunday then + (* The last Sunday before Advent always keeps the 24th (Last) Mass. *) + Some "ef-time-after-pentecost-sunday-24" + else if n > 23 then + (* Surplus Sundays resume the Sundays after Epiphany that Septuagesima + cut short -- the highest-numbered ones, so the 6th sits just before + the Last. *) + let total = match week last_sunday with Some t -> t | None -> n in + Some (Printf.sprintf "ef-time-after-epiphany-sunday-%d" (n - total + 7)) + else Some (Printf.sprintf "ef-time-after-pentecost-sunday-%d" n)) | _ -> ( match week d with | Some n -> Some (Printf.sprintf "ef-%s-sunday-%d" (season_slug_word s) n) -- cgit v1.3