Skip to content

Commit

Permalink
Add special_holidays_observed support (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico committed Oct 28, 2023
1 parent 142cbcc commit ab49501
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
10 changes: 5 additions & 5 deletions holidays/countries/albania.py
Expand Up @@ -9,7 +9,7 @@
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from holidays.calendars.gregorian import MAR
from holidays.calendars.gregorian import JAN, MAR
from holidays.calendars.julian import JULIAN_CALENDAR
from holidays.groups import (
ChristianHolidays,
Expand Down Expand Up @@ -91,10 +91,6 @@ def _populate(self, year):
if self.observed:
self._populate_observed(dts_observed)

# Observed holidays special cases.
if year == 2007:
self._add_holiday_jan_3(self.observed_label % "Eid al-Adha")


class AL(Albania):
pass
Expand All @@ -108,3 +104,7 @@ class AlbaniaStaticHolidays:
special_holidays = {
2022: (MAR, 21, "Public Holiday"),
}

special_holidays_observed = {
2007: (JAN, 3, "Eid al-Adha"),
}
17 changes: 11 additions & 6 deletions holidays/countries/bahamas.py
Expand Up @@ -9,7 +9,7 @@
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from holidays.calendars.gregorian import SEP
from holidays.calendars.gregorian import SEP, DEC
from holidays.groups import ChristianHolidays, InternationalHolidays, StaticHolidays
from holidays.observed_holiday_base import (
ObservedHolidayBase,
Expand Down Expand Up @@ -115,11 +115,6 @@ def _populate_public_holidays(self):
# Boxing Day.
self._add_observed(self._add_christmas_day_two("Boxing Day"))

# New Year's Day observance overflow.
# This only applies to Pre-2012 observance.
if self.observed and self._year in {1979, 1984, 1990, 2001, 2007}:
self._add_new_years_eve("New Year's Day (Observed)")


class BS(Bahamas):
pass
Expand All @@ -134,3 +129,13 @@ class BahamasStaticHolidays:
# https://www.bahamas.gov.bs/wps/portal/public/gov/government/notices/national%20holiday%2019th%20september/ # noqa: E501
2022: (SEP, 19, "State Funeral of Queen Elizabeth II"),
}

special_holidays_observed = {
# New Year's Day observance overflow.
# This only applies to Pre-2012 observance.
1979: (DEC, 31, "New Year's Day"),
1984: (DEC, 31, "New Year's Day"),
1990: (DEC, 31, "New Year's Day"),
2001: (DEC, 31, "New Year's Day"),
2007: (DEC, 31, "New Year's Day"),
}
8 changes: 4 additions & 4 deletions holidays/countries/cameroon.py
Expand Up @@ -87,10 +87,6 @@ def _populate(self, year):
if self.observed:
self._populate_observed(dts_observed)

# Observed holidays special cases.
if year == 2007:
self._add_holiday_jan_2(self.observed_label % "Eid al-Adha")


class CM(Cameroon):
pass
Expand Down Expand Up @@ -186,3 +182,7 @@ class CameroonStaticHolidays:
(JUL, 19, "Public Holiday"),
),
}

special_holidays_observed = {
2007: (JAN, 2, "Eid al-Adha"),
}
11 changes: 6 additions & 5 deletions holidays/countries/saudi_arabia.py
Expand Up @@ -14,7 +14,7 @@
from gettext import gettext as tr
from typing import Set

from holidays.calendars.gregorian import FEB, SEP, NOV, THU, FRI, SAT
from holidays.calendars.gregorian import JAN, FEB, SEP, NOV, THU, FRI, SAT
from holidays.groups import IslamicHolidays, StaticHolidays
from holidays.observed_holiday_base import (
ObservedHolidayBase,
Expand Down Expand Up @@ -109,10 +109,6 @@ def _populate(self, year):
# Founding Day
self._add_observed(self._add_holiday(tr("يوم التأسيسي"), dt))

# observed holidays special case (Eid al-Fitr Holiday (observed))
if self.observed and year == 2001:
self._add_holiday_jan_1(self.tr(self.observed_label) % self.tr(eid_al_fitr_name))


class SA(SaudiArabia):
pass
Expand All @@ -127,3 +123,8 @@ class SaudiArabiaStaticHolidays:
# Celebrate the country's win against Argentina in the World Cup
2022: (NOV, 23, tr("يوم وطني")),
}

special_holidays_observed = {
# Eid al-Fitr Holiday
2001: (JAN, 1, tr("عطلة عيد الفطر")),
}
8 changes: 4 additions & 4 deletions holidays/countries/singapore.py
Expand Up @@ -142,10 +142,6 @@ def _populate(self, year) -> None:
if self.observed:
self._populate_observed(dts_observed)

# Observed holidays special cases (observed from previous year)
if year == 2007:
self._add_holiday_jan_2(self.observed_label % "Hari Raya Haji")


class SG(Singapore):
pass
Expand Down Expand Up @@ -310,3 +306,7 @@ class SingaporeStaticHolidays:
# https://www.straitstimes.com/singapore/politics/singapore-presidential-election-2023-polling-day-on-sept-1-nomination-day-on-aug-22
2023: (SEP, 1, "Polling Day"),
}

special_holidays_observed = {
2007: (JAN, 2, "Hari Raya Haji"),
}
9 changes: 5 additions & 4 deletions holidays/countries/south_africa.py
Expand Up @@ -73,10 +73,6 @@ def _populate(self, year):

self._add_observed(self._add_holiday_sep_24("Heritage Day"))

# Special holiday http://tiny.cc/za_y2k
if self.observed and year == 2000:
self._add_holiday_jan_3("Y2K changeover (Observed)")

# Historic public holidays no longer observed
if 1952 <= year <= 1973:
self._add_holiday_apr_6("Van Riebeeck's Day")
Expand Down Expand Up @@ -145,3 +141,8 @@ class SouthAfricaStaticHolidays:
2021: (NOV, 1, "Municipal elections"),
2022: (DEC, 27, "Public holiday by presidential decree"),
}

special_holidays_observed = {
# Special holiday http://tiny.cc/za_y2k
2000: (JAN, 3, "Y2K changeover"),
}
12 changes: 12 additions & 0 deletions holidays/observed_holiday_base.py
Expand Up @@ -14,6 +14,7 @@
from typing import Dict, Optional, Tuple, Set

from holidays.calendars.gregorian import MON, TUE, WED, THU, FRI, SAT, SUN
from holidays.helpers import _normalize_tuple
from holidays.holiday_base import DateArg, HolidayBase


Expand Down Expand Up @@ -155,3 +156,14 @@ def _populate_observed(self, dts: Set[date], multiple: bool = False) -> None:
self._add_observed(dt, name)
else:
self._add_observed(dt)

def _add_special_holidays(self):
super()._add_special_holidays()

if self.observed:
for month, day, name in _normalize_tuple(
getattr(self, "special_holidays_observed", {}).get(self._year, ())
):
self._add_holiday(
self.tr(self.observed_label) % self.tr(name), date(self._year, month, day)
)

0 comments on commit ab49501

Please sign in to comment.