aboutsummaryrefslogtreecommitdiff
path: root/internal/calendar/calendar.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 14:00:01 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 14:00:01 +0200
commit58b748340059a02e696f6a7168f81114ac0f99e9 (patch)
tree956cfb133c249a4086ea7aef07a0fc7173e9150f /internal/calendar/calendar.go
parentba5b6b54819b5dbea10213138d9f210373b2c629 (diff)
downloadlectio-58b748340059a02e696f6a7168f81114ac0f99e9.tar.gz
lectio-58b748340059a02e696f6a7168f81114ac0f99e9.zip
feat(calendar): Compute branches on Form (computeEF via temporalEF/precedenceEF)
Diffstat (limited to 'internal/calendar/calendar.go')
-rw-r--r--internal/calendar/calendar.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/internal/calendar/calendar.go b/internal/calendar/calendar.go
index 98dec43..e0f5217 100644
--- a/internal/calendar/calendar.go
+++ b/internal/calendar/calendar.go
@@ -6,11 +6,49 @@ import (
"time"
)
-// Compute returns the Ordinary Form liturgical day for date under the given
-// Selection, with the ordered layer stack supplying celebrations. It is pure
-// and total: any valid Gregorian date yields a LiturgicalDay.
+// Compute returns the liturgical day for date under the given Selection, with
+// the ordered layer stack supplying celebrations. It is pure and total: any
+// valid Gregorian date yields a LiturgicalDay. Selection.Form "old" computes the
+// Extraordinary Form (1962); anything else computes the Ordinary Form.
func Compute(date time.Time, sel Selection, layers []Layer) LiturgicalDay {
date = date.UTC().Truncate(24 * time.Hour)
+ if sel.Form == "old" {
+ return computeEF(date, sel, layers)
+ }
+ return computeOF(date, sel, layers)
+}
+
+// computeEF computes the Extraordinary Form (1962) day.
+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}}
+ for slug, rc := range merged {
+ cel := buildCelebration(slug, rc)
+ when, ok := celebrationDate(cel, date.Year(), sel)
+ if !ok {
+ continue
+ }
+ if sameDay(when, date) {
+ cands = append(cands, candidate{Cel: cel, Temporal: false, Season: td.Season})
+ }
+ }
+ obs, others := pickEF(cands)
+ day := LiturgicalDay{
+ Date: date, Season: td.Season, Week: td.Week, Weekday: date.Weekday(),
+ Observed: obs.Cel, Colour: colourOf(obs, td), ObservedBand: precedenceEF(obs),
+ }
+ for _, o := range others {
+ if o.Temporal {
+ continue
+ }
+ day.Others = append(day.Others, o.Cel)
+ }
+ return day
+}
+
+// computeOF computes the Ordinary Form day.
+func computeOF(date time.Time, sel Selection, layers []Layer) LiturgicalDay {
td := temporal(date, sel)
merged := mergeLayers(layers)