Skip to content

Commit

Permalink
Refactor Germany special holidays (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico committed Dec 22, 2023
1 parent 74c453e commit 80e40e7
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions holidays/countries/germany.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

from gettext import gettext as tr

from holidays.groups import ChristianHolidays, InternationalHolidays
from holidays.calendars.gregorian import MAY, OCT
from holidays.groups import ChristianHolidays, InternationalHolidays, StaticHolidays
from holidays.holiday_base import HolidayBase


class Germany(HolidayBase, ChristianHolidays, InternationalHolidays):
class Germany(HolidayBase, ChristianHolidays, InternationalHolidays, StaticHolidays):
"""Official holidays for Germany in its current form.
This class doesn't return any holidays before 1990-10-03.
Expand Down Expand Up @@ -76,6 +77,7 @@ class Germany(HolidayBase, ChristianHolidays, InternationalHolidays):
def __init__(self, *args, **kwargs) -> None:
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)
StaticHolidays.__init__(self, GermanyStaticHolidays)
super().__init__(*args, **kwargs)

def _populate_public_holidays(self):
Expand Down Expand Up @@ -104,10 +106,6 @@ def _populate_public_holidays(self):
# German Unity Day.
self._add_holiday_oct_3(tr("Tag der Deutschen Einheit"))

if self._year == 2017:
# Reformation Day.
self._add_holiday_oct_31(tr("Reformationstag"))

if self._year <= 1994:
# Repentance and Prayer Day.
self._add_holiday_1st_wed_before_nov_22(tr("Buß- und Bettag"))
Expand All @@ -129,8 +127,8 @@ def _populate_subdiv_bb_public_holidays(self):
# Whit Sunday.
self._add_whit_sunday(tr("Pfingstsonntag"))

if self._year != 2017:
self._add_holiday_oct_31(tr("Reformationstag"))
# Reformation Day.
self._add_holiday_oct_31(tr("Reformationstag"))

def _populate_subdiv_be_public_holidays(self):
if self._year <= 1989:
Expand All @@ -140,16 +138,6 @@ def _populate_subdiv_be_public_holidays(self):
# International Women's Day.
self._add_womens_day(tr("Internationaler Frauentag"))

if self._year == 2020:
self._add_holiday_may_8(
# 75th anniversary of the liberation from Nazism and
# the end of the Second World War in Europe.
tr(
"75. Jahrestag der Befreiung vom Nationalsozialismus "
"und der Beendigung des Zweiten Weltkriegs in Europa"
),
)

def _populate_subdiv_bw_public_holidays(self):
if self._year <= 1989:
return None
Expand Down Expand Up @@ -215,8 +203,7 @@ def _populate_subdiv_mv_public_holidays(self):
if self._year >= 2023:
self._add_womens_day(tr("Internationaler Frauentag"))

if self._year != 2017:
self._add_holiday_oct_31(tr("Reformationstag"))
self._add_holiday_oct_31(tr("Reformationstag"))

def _populate_subdiv_ni_public_holidays(self):
if self._year <= 1989:
Expand Down Expand Up @@ -264,8 +251,7 @@ def _populate_subdiv_sn_public_holidays(self):
if self._year <= 1989:
return None

if self._year != 2017:
self._add_holiday_oct_31(tr("Reformationstag"))
self._add_holiday_oct_31(tr("Reformationstag"))

if self._year >= 1995:
# last wednesday before year-11-23
Expand All @@ -278,8 +264,7 @@ def _populate_subdiv_st_public_holidays(self):
if self._year >= 1991:
self._add_epiphany_day(tr("Heilige Drei Könige"))

if self._year != 2017:
self._add_holiday_oct_31(tr("Reformationstag"))
self._add_holiday_oct_31(tr("Reformationstag"))

def _populate_subdiv_th_public_holidays(self):
if self._year <= 1989:
Expand All @@ -289,8 +274,7 @@ def _populate_subdiv_th_public_holidays(self):
# World Children's Day.
self._add_holiday_sep_20(tr("Weltkindertag"))

if self._year != 2017:
self._add_holiday_oct_31(tr("Reformationstag"))
self._add_holiday_oct_31(tr("Reformationstag"))


class DE(Germany):
Expand All @@ -299,3 +283,22 @@ class DE(Germany):

class DEU(Germany):
pass


class GermanyStaticHolidays:
special_public_holidays = {
2017: (OCT, 31, tr("Reformationstag")),
}

special_be_public_holidays = {
2020: (
MAY,
8,
# 75th anniversary of the liberation from Nazism and
# the end of the Second World War in Europe.
tr(
"75. Jahrestag der Befreiung vom Nationalsozialismus "
"und der Beendigung des Zweiten Weltkriegs in Europa"
),
),
}

0 comments on commit 80e40e7

Please sign in to comment.