288 lines
13 KiB
Go
288 lines
13 KiB
Go
// Package liturgy implements the local liturgical calendar and the optional
|
||
// online source www.eucharistiefeier.de used by LektorenPlan.
|
||
package liturgy
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
"time"
|
||
|
||
"lektorenplan/domain"
|
||
)
|
||
|
||
// Moveable feasts -----------------------------------------------------------
|
||
|
||
func EasterSunday(year int) time.Time { return domain.EasterSunday(year) }
|
||
func AshWednesday(y int) time.Time { return domain.AshWednesday(y) }
|
||
func PalmSunday(y int) time.Time { return domain.PalmSunday(y) }
|
||
func HolyThursday(y int) time.Time { return domain.HolyThursday(y) }
|
||
func GoodFriday(y int) time.Time { return domain.GoodFriday(y) }
|
||
func HolySaturday(y int) time.Time { return domain.HolySaturday(y) }
|
||
func Ascension(y int) time.Time { return domain.Ascension(y) }
|
||
func Pentecost(y int) time.Time { return domain.Pentecost(y) }
|
||
func CorpusChristi(y int) time.Time { return domain.CorpusChristi(y) }
|
||
func SacredHeart(y int) time.Time { return domain.SacredHeart(y) }
|
||
func TrinitySunday(y int) time.Time { return domain.TrinitySunday(y) }
|
||
func AdventStart(year int) time.Time { return domain.AdventStart(year) }
|
||
func ChristKing(year int) time.Time { return domain.ChristKing(year) }
|
||
func BaptismOfTheLord(year int) time.Time { return domain.BaptismOfTheLord(year) }
|
||
|
||
// Seasons -------------------------------------------------------------------
|
||
|
||
func SeasonFor(date time.Time) domain.LiturgicalSeason { return domain.SeasonFor(date) }
|
||
func SeasonName(date time.Time) string { return SeasonFor(date).Title() }
|
||
|
||
// Obligation ----------------------------------------------------------------
|
||
|
||
func IsObligation(date time.Time, title string) bool {
|
||
if domain.IsSunday(date) {
|
||
return true
|
||
}
|
||
m, d := domain.Month(date), domain.DayNumber(date)
|
||
switch {
|
||
case m == 1 && d == 1, m == 1 && d == 6, m == 8 && d == 15, m == 11 && d == 1, m == 12 && d == 25:
|
||
return true
|
||
}
|
||
lower := strings.ToLower(title)
|
||
if strings.Contains(lower, "fronleichnam") ||
|
||
strings.Contains(lower, "christi himmelfahrt") ||
|
||
(strings.Contains(lower, "pfingsten") && !strings.Contains(lower, "vorabend")) ||
|
||
strings.Contains(lower, "ostersonntag") || strings.Contains(lower, "osternacht") {
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
|
||
// Symbols -------------------------------------------------------------------
|
||
|
||
func SymbolFor(title string, rank domain.LiturgicalRank, date time.Time) domain.FeastSymbol {
|
||
return domain.SymbolFor(title, rank, date)
|
||
}
|
||
|
||
// Local fallback ------------------------------------------------------------
|
||
|
||
var fixedReadings = map[string]domain.Readings{
|
||
"01-01": {First: "Num 6, 22-27", Psalm: "Ps 67 (66), 2-3.5.6 u. 8 (R: 2a)", Second: "Gal 4, 4-7", Gospel: "Lk 2, 16-21"},
|
||
"01-06": {First: "Jes 60, 1-6", Psalm: "Ps 72 (71), 1-2.7-8.10-11.12-13 (R: 11)", Second: "Eph 3, 2-3a.5-6", Gospel: "Mt 2, 1-12"},
|
||
"02-02": {First: "Mal 3, 1-4", Psalm: "Ps 24 (23), 7-8.9-10 (R: 8a)", Second: "Hebr 2, 14-18", Gospel: "Lk 2, 22-40"},
|
||
"03-19": {First: "2 Sam 7, 4-5a.12-14a.16", Psalm: "Ps 89 (88), 2-3.4-5.27.29 (R: 37)", Second: "Röm 4, 13.16-18.22", Gospel: "Mt 1, 16.18-21.24a"},
|
||
"03-25": {First: "Jes 7, 10-14", Psalm: "Ps 40 (39), 5-6.7-8a.8b-10 (R: 8a.9a)", Second: "Hebr 10, 4-10", Gospel: "Lk 1, 26-38"},
|
||
"06-24": {First: "Jes 49, 1-6", Psalm: "Ps 139 (138), 1-3.13-14ab.14c-15 (R: 14a)", Second: "Apg 13, 22-26", Gospel: "Lk 1, 57-66.80"},
|
||
"06-29": {First: "Apg 12, 1-11", Psalm: "Ps 34 (33), 2-3.4-5.6-7.8-9 (R: 5b)", Second: "2 Tim 4, 6-8.17-18", Gospel: "Mt 16, 13-19"},
|
||
"08-15": {First: "Offb 11, 19a; 12, 1-6a.10ab", Psalm: "Ps 45 (44), 11-12.16-17 (R: 10b)", Second: "1 Kor 15, 20-27", Gospel: "Lk 1, 39-56"},
|
||
"09-14": {First: "Num 21, 4b-9", Psalm: "Ps 78 (77), 1-2.34-35.36-37.38 (R: 7b)", Second: "Phil 2, 6-11", Gospel: "Joh 3, 13-17"},
|
||
"11-01": {First: "Offb 7, 2-4.9-14", Psalm: "Ps 24 (23), 1-2.3-4.5-6 (R: vgl. 6)", Second: "1 Joh 3, 1-3", Gospel: "Mt 5, 1-12a"},
|
||
"11-02": {First: "Jes 25, 6a.7-9", Psalm: "Ps 23 (22), 1-3a.3b-4.5.6 (R: 1)", Second: "Röm 8, 14-23", Gospel: "Mt 25, 31-46"},
|
||
"12-08": {First: "Gen 3, 9-15.20", Psalm: "Ps 98 (97), 1.2-3ab.3cd-4 (R: 1a)", Second: "Eph 1, 3-6.11-12", Gospel: "Lk 1, 26-38"},
|
||
"12-24": {First: "2 Sam 7, 1-5.8b-12.14a.16", Psalm: "Ps 89 (88), 2-3.20a u. 4-5.27 u. 29 (R: 2a)", Gospel: "Lk 1, 67-79"},
|
||
"12-25": {First: "Jes 52, 7-10", Psalm: "Ps 98 (97), 1.2-3b.3c-4.5-6 (R: vgl. 3cd)", Second: "Hebr 1, 1-6", Gospel: "Joh 1, 1-18"},
|
||
"12-26": {First: "Apg 6, 8-10; 7, 54-59", Psalm: "Ps 31 (30), 3-4.6.8.17 (R: 6a)", Gospel: "Mt 10, 17-22"},
|
||
}
|
||
|
||
var easterReadings = map[int]domain.Readings{
|
||
-46: {First: "Joel 2, 12-18", Psalm: "Ps 51 (50), 3-4.5-6a.12-13.14 u. 17 (R: vgl. 3a)", Second: "2 Kor 5, 20 - 6, 2", Gospel: "Mt 6, 1-6.16-18"},
|
||
-7: {First: "Jes 50, 4-7", Psalm: "Ps 22 (21), 8-9.17-18a.19-20.23-24 (R: 2a)", Second: "Phil 2, 6-11", Gospel: "Mt 21, 1-11"},
|
||
-3: {First: "Ex 12, 1-8.11-14", Psalm: "Ps 116 (115), 12-13.15-16bc.17-18 (R: vgl. 1 Kor 10, 16)", Second: "1 Kor 11, 23-26", Gospel: "Joh 13, 1-15"},
|
||
-2: {First: "Jes 52, 13 - 53, 12", Psalm: "Ps 31 (30), 2 u. 6.12-13.15-16.17 u. 25 (R: Lk 23, 46)", Second: "Hebr 4, 14-16; 5, 7-9", Gospel: "Joh 18, 1 - 19, 42"},
|
||
0: {First: "Apg 10, 34a.37-43", Psalm: "Ps 118 (117), 1-2.16-17.22-23 (R: vgl. 24)", Second: "Kol 3, 1-4 oder 1 Kor 5, 6b-8", Gospel: "Joh 20, 1-9"},
|
||
39: {First: "Apg 1, 1-11", Psalm: "Ps 47 (46), 2-3.6-7.8-9 (R: 6)", Second: "Eph 1, 17-23", Gospel: "Mk 16, 15-20"},
|
||
49: {First: "Apg 2, 1-11", Psalm: "Ps 104 (103), 1-2.24-25.29-30.31 u. 34 (R: vgl. 30)", Second: "1 Kor 12, 3b-7.12-13", Gospel: "Joh 20, 19-23"},
|
||
56: {First: "Spr 8, 22-31", Psalm: "Ps 8, 4-5.6-7.8-9 (R: 2a)", Second: "Röm 5, 1-5", Gospel: "Joh 16, 12-15"},
|
||
60: {First: "Dtn 8, 2-3.14-16a", Psalm: "Ps 147, 12-13.14-15.19-20 (R: 12a)", Second: "1 Kor 10, 16-17", Gospel: "Joh 6, 51-58"},
|
||
68: {First: "Hos 11, 1.3-4.8c-9", Psalm: "Jes 12, 2-3.4bcd.5-6 (R: 3)", Second: "Eph 3, 8-12.14-19", Gospel: "Joh 19, 31-37"},
|
||
}
|
||
|
||
// LocalDay builds the offline fallback for one date.
|
||
func LocalDay(date time.Time) domain.LiturgicalDay {
|
||
day := domain.Normalize(date)
|
||
y := domain.Year(day)
|
||
m := domain.Month(day)
|
||
d := domain.DayNumber(day)
|
||
key := fmt.Sprintf("%02d-%02d", m, d)
|
||
weekday := domain.Weekday(day)
|
||
easter := EasterSunday(y)
|
||
offset := domain.DaysBetween(easter, day)
|
||
|
||
title := ""
|
||
rank := domain.RankWeekday
|
||
color := domain.ColorGreen
|
||
readings := domain.Readings{}
|
||
remark := ""
|
||
|
||
switch offset {
|
||
case -46:
|
||
title, rank, color, readings = "Aschermittwoch", domain.RankWeekday, domain.ColorViolet, easterReadings[-46]
|
||
case -7:
|
||
title, rank, color, readings = "Palmsonntag", domain.RankFeast, domain.ColorRed, easterReadings[-7]
|
||
case -3:
|
||
title, rank, color, readings = "Gründonnerstag", domain.RankSolemnity, domain.ColorWhite, easterReadings[-3]
|
||
case -2:
|
||
title, rank, color, readings = "Karfreitag", domain.RankSolemnity, domain.ColorRed, easterReadings[-2]
|
||
case -1:
|
||
title, rank, color = "Karsamstag", domain.RankWeekday, domain.ColorViolet
|
||
case 0:
|
||
title, rank, color, readings = "Ostersonntag", domain.RankSolemnity, domain.ColorWhite, easterReadings[0]
|
||
remark = "Hochfest der Auferstehung des Herrn"
|
||
case 1:
|
||
title, rank, color = "Ostermontag", domain.RankSolemnity, domain.ColorWhite
|
||
readings = domain.Readings{First: "Apg 2, 14.22-33", Psalm: "Ps 16 (15), 1-2a u. 5.7-8.9-10.11 (R: 11a)", Gospel: "Mt 28, 8-15"}
|
||
case 39:
|
||
title, rank, color, readings = "Christi Himmelfahrt", domain.RankSolemnity, domain.ColorWhite, easterReadings[39]
|
||
case 49:
|
||
title, rank, color, readings = "Pfingsten", domain.RankSolemnity, domain.ColorRed, easterReadings[49]
|
||
remark = "Hochfest des Heiligen Geistes"
|
||
case 50:
|
||
title, rank, color = "Pfingstmontag", domain.RankSolemnity, domain.ColorRed
|
||
readings = domain.Readings{First: "Apg 10, 34a.37-43", Psalm: "Ps 118 (117), 1-2.16-17.22-23 (R: vgl. 24)", Second: "Kol 3, 1-4", Gospel: "Joh 20, 1-9"}
|
||
case 56:
|
||
title, rank, color, readings = "Dreifaltigkeitssonntag", domain.RankSolemnity, domain.ColorWhite, easterReadings[56]
|
||
case 60:
|
||
title, rank, color, readings = "Fronleichnam", domain.RankSolemnity, domain.ColorWhite, easterReadings[60]
|
||
remark = "Hochfest des Leibes und Blutes Christi"
|
||
case 68:
|
||
title, rank, color, readings = "Heiligstes Herz Jesu", domain.RankSolemnity, domain.ColorWhite, easterReadings[68]
|
||
}
|
||
|
||
if title == "" {
|
||
switch key {
|
||
case "01-01":
|
||
title, rank, color = "Neujahr – Hochfest der Gottesmutter Maria", domain.RankSolemnity, domain.ColorWhite
|
||
case "01-06":
|
||
title, rank, color = "Erscheinung des Herrn", domain.RankSolemnity, domain.ColorWhite
|
||
case "02-02":
|
||
title, rank, color = "Darstellung des Herrn", domain.RankFeast, domain.ColorWhite
|
||
case "03-19":
|
||
title, rank, color = "Hl. Josef, Bräutigam der Gottesmutter", domain.RankSolemnity, domain.ColorWhite
|
||
case "03-25":
|
||
title, rank, color = "Verkündigung des Herrn", domain.RankSolemnity, domain.ColorWhite
|
||
case "06-24":
|
||
title, rank, color = "Geburt Johannes' des Täufers", domain.RankSolemnity, domain.ColorWhite
|
||
case "06-29":
|
||
title, rank, color = "Petrus und Paulus", domain.RankSolemnity, domain.ColorRed
|
||
case "08-15":
|
||
title, rank, color = "Mariä Aufnahme in den Himmel", domain.RankSolemnity, domain.ColorWhite
|
||
case "09-14":
|
||
title, rank, color = "Kreuzerhöhung", domain.RankFeast, domain.ColorRed
|
||
case "11-01":
|
||
title, rank, color = "Allerheiligen", domain.RankSolemnity, domain.ColorWhite
|
||
case "11-02":
|
||
title, rank, color = "Allerseelen", domain.RankWeekday, domain.ColorViolet
|
||
case "12-08":
|
||
title, rank, color = "Mariä Empfängnis", domain.RankSolemnity, domain.ColorWhite
|
||
case "12-24":
|
||
title, rank, color = "Heiliger Abend", domain.RankWeekday, domain.ColorWhite
|
||
case "12-25":
|
||
title, rank, color = "Weihnachten – Hochfest der Geburt des Herrn", domain.RankSolemnity, domain.ColorWhite
|
||
case "12-26":
|
||
title, rank, color = "Hl. Stephanus", domain.RankFeast, domain.ColorRed
|
||
}
|
||
if r, ok := fixedReadings[key]; ok {
|
||
readings = r
|
||
}
|
||
}
|
||
|
||
if title == "" {
|
||
if weekday == 1 {
|
||
title = sundayTitle(day)
|
||
color = domain.ColorGreen
|
||
if seasonal := seasonalSundayRank(day); seasonal != domain.RankWeekday {
|
||
rank = seasonal
|
||
}
|
||
} else {
|
||
title = weekdayTitle(day)
|
||
season := SeasonFor(day)
|
||
if season == domain.SeasonAdvent || season == domain.SeasonLent {
|
||
color = domain.ColorViolet
|
||
} else if season == domain.SeasonChristmas || season == domain.SeasonEaster {
|
||
color = domain.ColorWhite
|
||
} else {
|
||
color = domain.ColorGreen
|
||
}
|
||
}
|
||
}
|
||
|
||
if rank == domain.RankSolemnity {
|
||
color = domain.ColorWhite
|
||
}
|
||
if rank == domain.RankFeast && color == domain.ColorGreen {
|
||
color = domain.ColorRed
|
||
}
|
||
|
||
return domain.LiturgicalDay{
|
||
Date: day, Title: title, Rank: rank, Color: color, Remark: remark,
|
||
Readings: readings, IsObligation: IsObligation(day, title),
|
||
Source: "lokale Berechnung", UpdatedAt: domain.Normalize(time.Now()),
|
||
}
|
||
}
|
||
|
||
func LocalDays(r domain.DayRange) []domain.LiturgicalDay {
|
||
days := r.Days()
|
||
out := make([]domain.LiturgicalDay, 0, len(days))
|
||
for _, day := range days {
|
||
out = append(out, LocalDay(day))
|
||
}
|
||
return out
|
||
}
|
||
|
||
func seasonalSundayRank(day time.Time) domain.LiturgicalRank {
|
||
season := SeasonFor(day)
|
||
if season == domain.SeasonAdvent || season == domain.SeasonChristmas || season == domain.SeasonLent || season == domain.SeasonEaster {
|
||
if season == domain.SeasonLent && domain.DaysBetween(PalmSunday(domain.Year(day)), day) == 0 {
|
||
return domain.RankFeast
|
||
}
|
||
return domain.RankWeekday
|
||
}
|
||
return domain.RankWeekday
|
||
}
|
||
|
||
func sundayTitle(day time.Time) string {
|
||
y := domain.Year(day)
|
||
switch SeasonFor(day) {
|
||
case domain.SeasonAdvent:
|
||
index := domain.DaysBetween(AdventStart(y), day)/7 + 1
|
||
names := []string{"1. Adventssonntag", "2. Adventssonntag", "3. Adventssonntag", "4. Adventssonntag"}
|
||
if index >= 1 && index <= len(names) {
|
||
return names[index-1]
|
||
}
|
||
return "Adventssonntag"
|
||
case domain.SeasonChristmas:
|
||
if domain.DaysBetween(BaptismOfTheLord(y), day) == 0 {
|
||
return "Taufe des Herrn"
|
||
}
|
||
return "Sonntag in der Weihnachtszeit"
|
||
case domain.SeasonLent:
|
||
index := domain.DaysBetween(AshWednesday(y), day)/7 + 1
|
||
if index >= 6 {
|
||
return "Palmsonntag"
|
||
}
|
||
return fmt.Sprintf("%d. Fastensonntag", index)
|
||
case domain.SeasonEaster:
|
||
index := domain.DaysBetween(EasterSunday(y), day)/7 + 1
|
||
if index == 1 {
|
||
return "Ostersonntag"
|
||
}
|
||
if index == 8 {
|
||
return "Pfingsten"
|
||
}
|
||
return fmt.Sprintf("%d. Sonntag der Osterzeit", index)
|
||
default:
|
||
return "Sonntag im Jahreskreis"
|
||
}
|
||
}
|
||
|
||
func weekdayTitle(day time.Time) string {
|
||
name := domain.WeekdayName(day)
|
||
switch SeasonFor(day) {
|
||
case domain.SeasonAdvent:
|
||
return name + " im Advent"
|
||
case domain.SeasonChristmas:
|
||
return name + " in der Weihnachtszeit"
|
||
case domain.SeasonLent:
|
||
return name + " in der Fastenzeit"
|
||
case domain.SeasonEaster:
|
||
return name + " in der Osterzeit"
|
||
default:
|
||
return name + " im Jahreskreis"
|
||
}
|
||
}
|