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
28 changes: 28 additions & 0 deletions holidays/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,31 @@
WEEKEND = (SAT, SUN)

JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC = range(1, 13)

# Supported holiday categories.
BANK = "bank"
EXTENDED = "extended"
GOVERNMENT = "government"
HALF_DAY = "half_day"
PUBLIC = "public"
SCHOOL = "school"

CHINESE = "chinese"
CHRISTIAN = "christian"
HEBREW = "hebrew"
HINDU = "hindu"
ISLAMIC = "islamic"

ALL_CATEGORIES = {
BANK,
CHINESE,
CHRISTIAN,
EXTENDED,
GOVERNMENT,
HALF_DAY,
HEBREW,
HINDU,
ISLAMIC,
PUBLIC,
SCHOOL,
}
21 changes: 15 additions & 6 deletions holidays/countries/austria.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

from gettext import gettext as tr

from holidays.constants import OCT, NOV
from holidays.constants import OCT, NOV, BANK, PUBLIC
from holidays.holiday_base import HolidayBase
from holidays.holiday_groups import ChristianHolidays, InternationalHolidays


class Austria(HolidayBase, ChristianHolidays, InternationalHolidays):
country = "AT"
default_language = "de"
supported_categories = {BANK, PUBLIC}
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_public_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
39 changes: 37 additions & 2 deletions holidays/holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@

from dateutil.parser import parse

from holidays.constants import HOLIDAY_NAME_DELIMITER, MON, TUE, WED, THU, FRI, SAT, SUN
from holidays.constants import (
HOLIDAY_NAME_DELIMITER,
MON,
TUE,
WED,
THU,
FRI,
SAT,
SUN,
ALL_CATEGORIES,
PUBLIC,
)
from holidays.helpers import _normalize_tuple

DateArg = Union[date, Tuple[int, int]]
Expand Down Expand Up @@ -211,6 +222,10 @@ def _populate(self, year):
"""Country weekend days."""
default_language: Optional[str] = None
"""The entity language used by default."""
categories: Optional[Set[str]] = None
arkid15r marked this conversation as resolved.
Show resolved Hide resolved
"""Requested holiday categories."""
supported_categories: Set[str] = set()
"""All holiday categories supported by this entity."""
supported_languages: Tuple[str, ...] = ()
"""All languages supported by this entity."""

Expand All @@ -223,6 +238,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 @@ -253,6 +269,9 @@ def __init__(
language translation is not supported the original holiday names
will be used.

:param categories:
Requested holiday categories.

:return:
A :class:`HolidayBase` object matching the **country**.
"""
Expand All @@ -262,6 +281,7 @@ def __init__(
self.language = language.lower() if language else None
self.observed = observed
self.subdiv = subdiv or prov or state
self.categories = set(categories) if categories else {PUBLIC}

self.tr = gettext # Default translation method.

Expand All @@ -288,6 +308,12 @@ def __init__(
DeprecationWarning,
)

unknown_categories = self.categories.difference(ALL_CATEGORIES)
if len(unknown_categories) > 0:
raise NotImplementedError(
f"Category is not supported: {', '.join(unknown_categories)}."
)

name = getattr(self, "country", getattr(self, "market", None))
if name:
locale_dir = os.path.join(os.path.dirname(__file__), "locale")
Expand Down Expand Up @@ -485,7 +511,7 @@ def __repr__(self) -> str:
def __setattr__(self, key: str, value: Any) -> None:
dict.__setattr__(self, key, value)

if self and key == "observed":
if self and key in {"categories", "observed"}:
self.clear()
for year in self.years: # Re-populate holidays for each year.
self._populate(year)
Expand Down Expand Up @@ -628,11 +654,20 @@ def _populate(self, year: int) -> Set[Optional[date]]:
for month, day, name in _normalize_tuple(self.special_holidays.get(year, ())):
dates.add(self._add_holiday(name, date(year, month, day)))

# Populate categories holidays.
self._populate_categories()

# Populate subdivision holidays.
self._add_subdiv_holidays()

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