Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce holiday categories support #1320

Merged
merged 12 commits into from
Jun 28, 2023
19 changes: 14 additions & 5 deletions holidays/countries/austria.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class Austria(HolidayBase, ChristianHolidays, InternationalHolidays):
country = "AT"
default_language = "de"
supported_categories = ("bank", "common")
KJhellico marked this conversation as resolved.
Show resolved Hide resolved
supported_languages = ("de", "en_US", "uk")
subdivisions = ("1", "2", "3", "4", "5", "6", "7", "8", "9")

Expand All @@ -32,9 +33,7 @@ def __init__(self, *args, **kwargs) -> None:
kwargs["subdiv"] = "9"
super().__init__(*args, **kwargs)

def _populate(self, year):
super()._populate(year)

def _populate_common_holidays(self):
# New Year's Day.
self._add_new_years_day(tr("Neujahr"))

Expand All @@ -59,10 +58,10 @@ def _populate(self, year):
# Assumption Day.
self._add_assumption_of_mary_day(tr("Mariä Himmelfahrt"))

if 1919 <= year <= 1934:
if 1919 <= self._year <= 1934:
# National Day.
self._add_holiday(tr("Nationalfeiertag"), NOV, 12)
if year >= 1967:
if self._year >= 1967:
self._add_holiday(tr("Nationalfeiertag"), OCT, 26)

# All Saints' Day.
Expand All @@ -77,6 +76,16 @@ def _populate(self, year):
# St. Stephen's Day.
self._add_christmas_day_two(tr("Stefanitag"))

def _populate_bank_holidays(self):
# Good Friday.
self._add_good_friday(tr("Karfreitag"))

# Christmas Eve.
self._add_christmas_eve(tr("Heiliger Abend"))

# New Year's Eve.
self._add_new_years_eve(tr("Silvester"))


class AT(Austria):
pass
Expand Down
15 changes: 15 additions & 0 deletions holidays/holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def _populate(self, year):
"""Country weekend days."""
default_language: Optional[str] = None
"""The entity language used by default."""
categories: Optional[Tuple[str]] = None
KJhellico marked this conversation as resolved.
Show resolved Hide resolved
"""Requested holiday categories"""
KJhellico marked this conversation as resolved.
Show resolved Hide resolved
supported_categories: Tuple[str, ...] = ()
"""All holiday categories supported by this entity"""
KJhellico marked this conversation as resolved.
Show resolved Hide resolved
supported_languages: Tuple[str, ...] = ()
"""All languages supported by this entity."""

Expand All @@ -223,6 +227,7 @@ def __init__(
prov: Optional[str] = None, # Deprecated.
state: Optional[str] = None, # Deprecated.
language: Optional[str] = None,
categories: Optional[Tuple[str]] = None,
KJhellico marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""
:param years:
Expand Down Expand Up @@ -262,6 +267,7 @@ def __init__(
self.language = language.lower() if language else None
self.observed = observed
self.subdiv = subdiv or prov or state
self.categories = categories or ("common",)

self.tr = gettext # Default translation method.

Expand Down Expand Up @@ -624,6 +630,9 @@ def _populate(self, year: int) -> Set[Optional[date]]:
self._year = year
dates = set()

# Populate categories holidays.
self._populate_categories()

# Populate items from the special holidays list.
for month, day, name in _normalize_tuple(self.special_holidays.get(year, ())):
dates.add(self._add_holiday(name, date(year, month, day)))
Expand All @@ -633,6 +642,12 @@ def _populate(self, year: int) -> Set[Optional[date]]:

return dates

def _populate_categories(self):
arkid15r marked this conversation as resolved.
Show resolved Hide resolved
for category in self.categories:
populate_category_holidays = getattr(self, f"_populate_{category}_holidays", None)
if populate_category_holidays and callable(populate_category_holidays):
populate_category_holidays()

def append(self, *args: Union[Dict[DateLike, str], List[DateLike], DateLike]) -> None:
"""Alias for :meth:`update` to mimic list type."""
return self.update(*args)
Expand Down
43 changes: 29 additions & 14 deletions holidays/locale/de/LC_MESSAGES/AT.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Authors: ~Jhellico <jhellico@gmail.com>, (c) 2023.
msgid ""
msgstr ""
"Project-Id-Version: Python Holidays 0.23\n"
"Project-Id-Version: Python Holidays 0.28\n"
"POT-Creation-Date: 2023-04-01 17:13+0300\n"
"PO-Revision-Date: 2023-04-01 17:15+0300\n"
"Last-Translator: ~Jhellico <jhellico@gmail.com>\n"
Expand All @@ -16,66 +16,81 @@ msgstr ""
"X-Generator: Poedit 3.2.2\n"

#. New Year's Day.
#: ./holidays/countries/austria.py:39
#: ./holidays/countries/austria.py:38
msgid "Neujahr"
msgstr ""

#. Epiphany.
#: ./holidays/countries/austria.py:42
#: ./holidays/countries/austria.py:41
msgid "Heilige Drei Könige"
msgstr ""

#. Easter Monday.
#: ./holidays/countries/austria.py:45
#: ./holidays/countries/austria.py:44
msgid "Ostermontag"
msgstr ""

#. Labor Day.
#: ./holidays/countries/austria.py:48
#: ./holidays/countries/austria.py:47
msgid "Staatsfeiertag"
msgstr ""

#. Ascension Day.
#: ./holidays/countries/austria.py:51
#: ./holidays/countries/austria.py:50
msgid "Christi Himmelfahrt"
msgstr ""

#. Whit Monday.
#: ./holidays/countries/austria.py:54
#: ./holidays/countries/austria.py:53
msgid "Pfingstmontag"
msgstr ""

#. Corpus Christi.
#: ./holidays/countries/austria.py:57
#: ./holidays/countries/austria.py:56
msgid "Fronleichnam"
msgstr ""

#. Assumption Day.
#: ./holidays/countries/austria.py:60
#: ./holidays/countries/austria.py:59
msgid "Mariä Himmelfahrt"
msgstr ""

#. National Day.
#: ./holidays/countries/austria.py:64 ./holidays/countries/austria.py:66
#: ./holidays/countries/austria.py:63 ./holidays/countries/austria.py:65
msgid "Nationalfeiertag"
msgstr ""

#. All Saints' Day.
#: ./holidays/countries/austria.py:69
#: ./holidays/countries/austria.py:68
msgid "Allerheiligen"
msgstr ""

#. Immaculate Conception.
#: ./holidays/countries/austria.py:72
#: ./holidays/countries/austria.py:71
msgid "Mariä Empfängnis"
msgstr ""

#. Christmas Day.
#: ./holidays/countries/austria.py:75
#: ./holidays/countries/austria.py:74
msgid "Christtag"
msgstr ""

#. St. Stephen's Day.
#: ./holidays/countries/austria.py:78
#: ./holidays/countries/austria.py:77
msgid "Stefanitag"
msgstr ""

#. Good Friday.
#: ./holidays/countries/austria.py:81
msgid "Karfreitag"
msgstr ""

#. Christmas Eve.
#: ./holidays/countries/austria.py:84
msgid "Heiliger Abend"
msgstr ""

#. New Year's Eve.
#: ./holidays/countries/austria.py:87
msgid "Silvester"
msgstr ""
43 changes: 29 additions & 14 deletions holidays/locale/en_US/LC_MESSAGES/AT.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Python Holidays 0.23\n"
"Project-Id-Version: Python Holidays 0.28\n"
"POT-Creation-Date: 2023-04-01 17:13+0300\n"
"PO-Revision-Date: 2023-04-01 17:18+0300\n"
"Last-Translator: ~Jhellico <jhellico@gmail.com>\n"
Expand All @@ -17,66 +17,81 @@ msgstr ""
"X-Generator: Poedit 3.2.2\n"

#. New Year's Day.
#: ./holidays/countries/austria.py:39
#: ./holidays/countries/austria.py:38
msgid "Neujahr"
msgstr "New Year's Day"

#. Epiphany.
#: ./holidays/countries/austria.py:42
#: ./holidays/countries/austria.py:41
msgid "Heilige Drei Könige"
msgstr "Epiphany"

#. Easter Monday.
#: ./holidays/countries/austria.py:45
#: ./holidays/countries/austria.py:44
msgid "Ostermontag"
msgstr "Easter Monday"

#. Labor Day.
#: ./holidays/countries/austria.py:48
#: ./holidays/countries/austria.py:47
msgid "Staatsfeiertag"
msgstr "Labor Day"

#. Ascension Day.
#: ./holidays/countries/austria.py:51
#: ./holidays/countries/austria.py:50
msgid "Christi Himmelfahrt"
msgstr "Ascension Day"

#. Whit Monday.
#: ./holidays/countries/austria.py:54
#: ./holidays/countries/austria.py:53
msgid "Pfingstmontag"
msgstr "Whit Monday"

#. Corpus Christi.
#: ./holidays/countries/austria.py:57
#: ./holidays/countries/austria.py:56
msgid "Fronleichnam"
msgstr "Corpus Christi"

#. Assumption Day.
#: ./holidays/countries/austria.py:60
#: ./holidays/countries/austria.py:59
msgid "Mariä Himmelfahrt"
msgstr "Assumption Day"

#. National Day.
#: ./holidays/countries/austria.py:64 ./holidays/countries/austria.py:66
#: ./holidays/countries/austria.py:63 ./holidays/countries/austria.py:65
msgid "Nationalfeiertag"
msgstr "National Day"

#. All Saints' Day.
#: ./holidays/countries/austria.py:69
#: ./holidays/countries/austria.py:68
msgid "Allerheiligen"
msgstr "All Saints' Day"

#. Immaculate Conception.
#: ./holidays/countries/austria.py:72
#: ./holidays/countries/austria.py:71
msgid "Mariä Empfängnis"
msgstr "Immaculate Conception"

#. Christmas Day.
#: ./holidays/countries/austria.py:75
#: ./holidays/countries/austria.py:74
msgid "Christtag"
msgstr "Christmas Day"

#. St. Stephen's Day.
#: ./holidays/countries/austria.py:78
#: ./holidays/countries/austria.py:77
msgid "Stefanitag"
msgstr "St. Stephen's Day"

#. Good Friday.
#: ./holidays/countries/austria.py:81
msgid "Karfreitag"
msgstr "Good Friday"

#. Christmas Eve.
#: ./holidays/countries/austria.py:84
msgid "Heiliger Abend"
msgstr "Christmas Eve"

#. New Year's Eve.
#: ./holidays/countries/austria.py:87
msgid "Silvester"
msgstr "New Year's Eve"
Loading