mirror of
https://github.com/Luzifer/go-holidays.git
synced 2024-12-26 05:41:18 +00:00
Restructure german holidays, fix missing days
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
0a030df36a
commit
9e3382f215
2 changed files with 110 additions and 111 deletions
|
@ -1,119 +1,95 @@
|
||||||
package holidays
|
package holidays
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerHolidayDataSource("de", holidaysDENational{})
|
registerHolidayDataSource("de", holidaysDE{})
|
||||||
registerHolidayDataSource("de-bb", holidaysDEBB{})
|
registerHolidayDataSource("de-bb", holidaysDE{state: "bb"})
|
||||||
registerHolidayDataSource("de-be", holidaysDEBE{})
|
registerHolidayDataSource("de-be", holidaysDE{state: "be"})
|
||||||
registerHolidayDataSource("de-bw", holidaysDEBW{})
|
registerHolidayDataSource("de-bw", holidaysDE{state: "bw"})
|
||||||
registerHolidayDataSource("de-by", holidaysDEBY{})
|
registerHolidayDataSource("de-by", holidaysDE{state: "by"})
|
||||||
registerHolidayDataSource("de-hb", holidaysDEHB{})
|
registerHolidayDataSource("de-hb", holidaysDE{state: "hb"})
|
||||||
registerHolidayDataSource("de-he", holidaysDEHE{})
|
registerHolidayDataSource("de-he", holidaysDE{state: "he"})
|
||||||
registerHolidayDataSource("de-hh", holidaysDEHH{})
|
registerHolidayDataSource("de-hh", holidaysDE{state: "hh"})
|
||||||
registerHolidayDataSource("de-mv", holidaysDEMV{})
|
registerHolidayDataSource("de-mv", holidaysDE{state: "mv"})
|
||||||
registerHolidayDataSource("de-ni", holidaysDENI{})
|
registerHolidayDataSource("de-ni", holidaysDE{state: "ni"})
|
||||||
registerHolidayDataSource("de-nw", holidaysDENW{})
|
registerHolidayDataSource("de-nw", holidaysDE{state: "nw"})
|
||||||
registerHolidayDataSource("de-rp", holidaysDERP{})
|
registerHolidayDataSource("de-rp", holidaysDE{state: "rp"})
|
||||||
registerHolidayDataSource("de-sh", holidaysDESH{})
|
registerHolidayDataSource("de-sh", holidaysDE{state: "sh"})
|
||||||
registerHolidayDataSource("de-sl", holidaysDESL{})
|
registerHolidayDataSource("de-sl", holidaysDE{state: "sl"})
|
||||||
registerHolidayDataSource("de-sn", holidaysDESN{})
|
registerHolidayDataSource("de-sn", holidaysDE{state: "sn"})
|
||||||
registerHolidayDataSource("de-st", holidaysDEST{})
|
registerHolidayDataSource("de-st", holidaysDE{state: "st"})
|
||||||
registerHolidayDataSource("de-th", holidaysDETH{})
|
registerHolidayDataSource("de-th", holidaysDE{state: "th"})
|
||||||
}
|
}
|
||||||
|
|
||||||
type holidaysDENational struct{}
|
type (
|
||||||
|
holidaysDE struct{ state string }
|
||||||
|
)
|
||||||
|
|
||||||
func (h holidaysDENational) GetIncludes() []string { return []string{} }
|
func (holidaysDE) GetIncludes() []string { return nil }
|
||||||
func (h holidaysDENational) GetHolidays(year int) []Holiday {
|
func (h holidaysDE) GetHolidays(year int) []Holiday {
|
||||||
return []Holiday{
|
var (
|
||||||
newHoliday("New Year's Day", map[string]string{"de": "Neujahrstag"}, dateFromNumbers(year, 1, 1)),
|
neujahr = newHoliday("New Year's Day", map[string]string{"de": "Neujahrstag"}, dateFromNumbers(year, 1, 1))
|
||||||
newHoliday("Labor Day", map[string]string{"de": "Tag der Arbeit"}, dateFromNumbers(year, 5, 1)),
|
hlDreiKoenige = newHoliday("Epiphany", map[string]string{"de": "Heilige Drei Könige"}, dateFromNumbers(year, 1, 6))
|
||||||
newHoliday("German Unity Day", map[string]string{"de": "Tag der Deutschen Einheit"}, dateFromNumbers(year, 10, 3)),
|
womansDay = newHoliday("International Women’s Day", map[string]string{"de": "Internationaler Frauentag"}, dateFromNumbers(year, 3, 8))
|
||||||
newHoliday("Christmas Day", map[string]string{"de": "Weihnachtstag"}, dateFromNumbers(year, 12, 25)),
|
tagDerArbeit = newHoliday("Labor Day", map[string]string{"de": "Tag der Arbeit"}, dateFromNumbers(year, 5, 1))
|
||||||
newHoliday("Boxing Day", map[string]string{"de": "Zweiter Weihnachtsfeiertag"}, dateFromNumbers(year, 12, 26)),
|
marHimmelfahrt = newHoliday("Assumption of Mary", map[string]string{"de": "Mariä Himmelfahrt"}, dateFromNumbers(year, 8, 15))
|
||||||
newHoliday("Good Friday", map[string]string{"de": "Karfreitag"}, GregorianEasterSunday(year).Add(-2*day)),
|
kinderTag = newHoliday("World Children's Day", map[string]string{"de": "Weltkindertag"}, dateFromNumbers(year, 9, 20))
|
||||||
newHoliday("Easter Sunday", map[string]string{"de": "Ostersonntag"}, GregorianEasterSunday(year)),
|
tagDerEinheit = newHoliday("German Unity Day", map[string]string{"de": "Tag der Deutschen Einheit"}, dateFromNumbers(year, 10, 3))
|
||||||
newHoliday("Easter Monday", map[string]string{"de": "Ostermontag"}, GregorianEasterSunday(year).Add(1*day)),
|
reformationsTag = newHoliday("Reformation Day", map[string]string{"de": "Reformationstag"}, dateFromNumbers(year, 10, 31))
|
||||||
newHoliday("Ascension Day", map[string]string{"de": "Christi Himmelfahrt"}, GregorianEasterSunday(year).Add(39*day)),
|
allerheiligen = newHoliday("All Saints", map[string]string{"de": "Allerheiligen"}, dateFromNumbers(year, 11, 1))
|
||||||
newHoliday("Whit Monday", map[string]string{"de": "Pfingstmontag"}, GregorianEasterSunday(year).Add(50*day)),
|
weihnacht1 = newHoliday("Christmas Day", map[string]string{"de": "Weihnachtstag"}, dateFromNumbers(year, 12, 25))
|
||||||
|
weihnacht2 = newHoliday("Boxing Day", map[string]string{"de": "Zweiter Weihnachtsfeiertag"}, dateFromNumbers(year, 12, 26))
|
||||||
|
|
||||||
|
karfreitag = newHoliday("Good Friday", map[string]string{"de": "Karfreitag"}, GregorianEasterSunday(year).Add(-2*day))
|
||||||
|
osterSonntag = newHoliday("Easter Sunday", map[string]string{"de": "Ostersonntag"}, GregorianEasterSunday(year))
|
||||||
|
osterMontag = newHoliday("Easter Monday", map[string]string{"de": "Ostermontag"}, GregorianEasterSunday(year).Add(1*day))
|
||||||
|
chrHimmelfahrt = newHoliday("Ascension Day", map[string]string{"de": "Christi Himmelfahrt"}, GregorianEasterSunday(year).Add(39*day))
|
||||||
|
pfingstMontag = newHoliday("Whit Monday", map[string]string{"de": "Pfingstmontag"}, GregorianEasterSunday(year).Add(50*day))
|
||||||
|
fronleichnam = newHoliday("Corpus Christi", map[string]string{"de": "Fronleichnam"}, GregorianEasterSunday(year).Add(60*day))
|
||||||
|
|
||||||
|
national = []Holiday{
|
||||||
|
neujahr, tagDerArbeit, tagDerEinheit, weihnacht1, weihnacht2,
|
||||||
|
karfreitag, osterSonntag, osterMontag, chrHimmelfahrt, pfingstMontag,
|
||||||
}
|
}
|
||||||
}
|
states = map[string][]Holiday{
|
||||||
|
"": national,
|
||||||
type holidaysDEBB struct{}
|
"bb": append(national, reformationsTag),
|
||||||
|
"be": append(national, womansDay),
|
||||||
func (h holidaysDEBB) GetIncludes() []string { return []string{"de"} }
|
"bw": append(national, hlDreiKoenige, fronleichnam, allerheiligen),
|
||||||
func (h holidaysDEBB) GetHolidays(year int) []Holiday {
|
"by": append(national, hlDreiKoenige, fronleichnam, marHimmelfahrt, allerheiligen),
|
||||||
return []Holiday{
|
"hb": append(national, reformationsTag),
|
||||||
newHoliday("Reformation Day", map[string]string{"de": "Reformationstag"}, dateFromNumbers(year, 10, 31)),
|
"he": append(national, fronleichnam),
|
||||||
|
"hh": append(national, reformationsTag),
|
||||||
|
"mv": append(national, reformationsTag),
|
||||||
|
"ni": append(national, reformationsTag),
|
||||||
|
"nw": append(national, fronleichnam, allerheiligen),
|
||||||
|
"rp": append(national, fronleichnam, allerheiligen),
|
||||||
|
"sh": append(national, reformationsTag),
|
||||||
|
"sl": append(national, fronleichnam, marHimmelfahrt, allerheiligen),
|
||||||
|
"sn": append(national, reformationsTag, h.getDRP(year)),
|
||||||
|
"st": append(national, hlDreiKoenige, reformationsTag),
|
||||||
|
"th": append(national, kinderTag, reformationsTag),
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return states[h.state]
|
||||||
}
|
}
|
||||||
|
|
||||||
type holidaysDEBE struct{ holidaysDENational }
|
func (holidaysDE) getDRP(year int) Holiday {
|
||||||
|
var (
|
||||||
|
day time.Time
|
||||||
|
dayN = 16
|
||||||
|
)
|
||||||
|
|
||||||
type holidaysDEBW struct{}
|
for {
|
||||||
|
day = dateFromNumbers(year, 11, dayN)
|
||||||
func (h holidaysDEBW) GetIncludes() []string { return []string{"de"} }
|
if day.Weekday() == time.Wednesday {
|
||||||
func (h holidaysDEBW) GetHolidays(year int) []Holiday {
|
break
|
||||||
return []Holiday{
|
|
||||||
newHoliday("Epiphany", map[string]string{"de": "Heilige Drei Könige"}, dateFromNumbers(year, 1, 6)),
|
|
||||||
newHoliday("All Saints", map[string]string{"de": "Allerheiligen"}, dateFromNumbers(year, 11, 1)),
|
|
||||||
newHoliday("Corpus Christi", map[string]string{"de": "Fronleichnam"}, GregorianEasterSunday(year).Add(60*day)),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type holidaysDEBY struct{ holidaysDEBW }
|
dayN++
|
||||||
|
|
||||||
type holidaysDEHB struct{ holidaysDENational }
|
|
||||||
|
|
||||||
type holidaysDEHE struct{}
|
|
||||||
|
|
||||||
func (h holidaysDEHE) GetIncludes() []string { return []string{"de"} }
|
|
||||||
func (h holidaysDEHE) GetHolidays(year int) []Holiday {
|
|
||||||
return []Holiday{
|
|
||||||
newHoliday("Corpus Christi", map[string]string{"de": "Fronleichnam"}, GregorianEasterSunday(year).Add(60*day)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newHoliday("Day of Repentance and Prayer", map[string]string{"de": "Buß- und Bettag"}, day)
|
||||||
}
|
}
|
||||||
|
|
||||||
type holidaysDEHH struct{ holidaysDENational }
|
|
||||||
|
|
||||||
type holidaysDEMV struct{ holidaysDEBB }
|
|
||||||
|
|
||||||
type holidaysDENI struct{ holidaysDENational }
|
|
||||||
|
|
||||||
type holidaysDENW struct{}
|
|
||||||
|
|
||||||
func (h holidaysDENW) GetIncludes() []string { return []string{"de"} }
|
|
||||||
func (h holidaysDENW) GetHolidays(year int) []Holiday {
|
|
||||||
return []Holiday{
|
|
||||||
newHoliday("All Saints", map[string]string{"de": "Allerheiligen"}, dateFromNumbers(year, 11, 1)),
|
|
||||||
newHoliday("Corpus Christi", map[string]string{"de": "Fronleichnam"}, GregorianEasterSunday(year).Add(60*day)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type holidaysDERP struct{ holidaysDENW }
|
|
||||||
|
|
||||||
type holidaysDESH struct{ holidaysDENational }
|
|
||||||
|
|
||||||
type holidaysDESL struct{}
|
|
||||||
|
|
||||||
func (h holidaysDESL) GetIncludes() []string { return []string{"de"} }
|
|
||||||
func (h holidaysDESL) GetHolidays(year int) []Holiday {
|
|
||||||
return []Holiday{
|
|
||||||
newHoliday("Assumption Day", map[string]string{"de": "Mariä Himmelfahrt"}, dateFromNumbers(year, 8, 15)),
|
|
||||||
newHoliday("All Saints", map[string]string{"de": "Allerheiligen"}, dateFromNumbers(year, 11, 1)),
|
|
||||||
newHoliday("Corpus Christi", map[string]string{"de": "Fronleichnam"}, GregorianEasterSunday(year).Add(60*day)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type holidaysDESN struct{ holidaysDEBB }
|
|
||||||
|
|
||||||
type holidaysDEST struct{}
|
|
||||||
|
|
||||||
func (h holidaysDEST) GetIncludes() []string { return []string{"de"} }
|
|
||||||
func (h holidaysDEST) GetHolidays(year int) []Holiday {
|
|
||||||
return []Holiday{
|
|
||||||
newHoliday("Epiphany", map[string]string{"de": "Heilige Drei Könige"}, dateFromNumbers(year, 1, 6)),
|
|
||||||
newHoliday("Reformation Day", map[string]string{"de": "Reformationstag"}, dateFromNumbers(year, 10, 31)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type holidaysDETH struct{ holidaysDEBB }
|
|
||||||
|
|
23
holidays/holidays_de_test.go
Normal file
23
holidays/holidays_de_test.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package holidays
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDRPDate(t *testing.T) {
|
||||||
|
for year, exp := range map[int]time.Time{
|
||||||
|
2021: dateFromNumbers(2021, 11, 17),
|
||||||
|
2022: dateFromNumbers(2022, 11, 16),
|
||||||
|
2023: dateFromNumbers(2023, 11, 22),
|
||||||
|
2024: dateFromNumbers(2024, 11, 20),
|
||||||
|
2025: dateFromNumbers(2025, 11, 19),
|
||||||
|
2026: dateFromNumbers(2026, 11, 18),
|
||||||
|
2027: dateFromNumbers(2027, 11, 17),
|
||||||
|
} {
|
||||||
|
h := holidaysDE{}.getDRP(year)
|
||||||
|
if !h.ParsedDate.Equal(exp) {
|
||||||
|
t.Errorf("DRP %d: Expected %s, got %s", year, exp, h.ParsedDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue