package caldata import ( "time" "github.com/lukaszkasprzak/lectio/internal/calendar" ) // Readings resolves a day's Mass readings: the observed celebration's inline // propers, else the temporal lectionary for its slug, else -- for an EF // weekday with no proper Mass -- the preceding Sunday's Mass (the 1962 rule // that green-season ferias repeat the Sunday). Shared by the CLI (cli.dayReadings // delegates here) and calfeed.Build (injected as its readings func). func Readings(sel calendar.Selection, layers []calendar.Layer, date time.Time, day calendar.LiturgicalDay) []calendar.Reading { var rs []calendar.Reading for _, m := range day.Observed.Masses { rs = append(rs, m.Readings...) } if len(rs) > 0 { return rs } // temporal table: EF by slug, OF by slug+cycle. key := day.Observed.Slug if sel.Form != "old" && day.SundayCycle != "" { key = day.Observed.Slug + "-" + day.SundayCycle } if r := TemporalReadings(sel.Form, key); len(r) > 0 { return r } if sel.Form == "old" && day.Observed.Layer == "temporal" && date.Weekday() != time.Sunday { sun := date.AddDate(0, 0, -int(date.Weekday())) // preceding Sunday (Sunday = 0) sd := calendar.Compute(sun, sel, layers) return TemporalReadings(sel.Form, sd.Observed.Slug) } return nil }