From ab495013ed87abbd1c819ccdc0700beb32c03ce3 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Sat, 28 Oct 2023 19:41:38 +0300 Subject: [PATCH] Add special_holidays_observed support (#1535) --- holidays/countries/albania.py | 10 +++++----- holidays/countries/bahamas.py | 17 +++++++++++------ holidays/countries/cameroon.py | 8 ++++---- holidays/countries/saudi_arabia.py | 11 ++++++----- holidays/countries/singapore.py | 8 ++++---- holidays/countries/south_africa.py | 9 +++++---- holidays/observed_holiday_base.py | 12 ++++++++++++ 7 files changed, 47 insertions(+), 28 deletions(-) diff --git a/holidays/countries/albania.py b/holidays/countries/albania.py index 596d052b2..9396530e7 100644 --- a/holidays/countries/albania.py +++ b/holidays/countries/albania.py @@ -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, @@ -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 @@ -108,3 +104,7 @@ class AlbaniaStaticHolidays: special_holidays = { 2022: (MAR, 21, "Public Holiday"), } + + special_holidays_observed = { + 2007: (JAN, 3, "Eid al-Adha"), + } diff --git a/holidays/countries/bahamas.py b/holidays/countries/bahamas.py index e92c7d9d8..c820091a3 100644 --- a/holidays/countries/bahamas.py +++ b/holidays/countries/bahamas.py @@ -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, @@ -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 @@ -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"), + } diff --git a/holidays/countries/cameroon.py b/holidays/countries/cameroon.py index 810842324..6ffd7ac13 100644 --- a/holidays/countries/cameroon.py +++ b/holidays/countries/cameroon.py @@ -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 @@ -186,3 +182,7 @@ class CameroonStaticHolidays: (JUL, 19, "Public Holiday"), ), } + + special_holidays_observed = { + 2007: (JAN, 2, "Eid al-Adha"), + } diff --git a/holidays/countries/saudi_arabia.py b/holidays/countries/saudi_arabia.py index 7b04a4efa..6a5c0d4fb 100644 --- a/holidays/countries/saudi_arabia.py +++ b/holidays/countries/saudi_arabia.py @@ -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, @@ -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 @@ -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("عطلة عيد الفطر")), + } diff --git a/holidays/countries/singapore.py b/holidays/countries/singapore.py index d322bff58..525ade352 100644 --- a/holidays/countries/singapore.py +++ b/holidays/countries/singapore.py @@ -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 @@ -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"), + } diff --git a/holidays/countries/south_africa.py b/holidays/countries/south_africa.py index 87e386b36..f29a7d64b 100644 --- a/holidays/countries/south_africa.py +++ b/holidays/countries/south_africa.py @@ -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") @@ -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"), + } diff --git a/holidays/observed_holiday_base.py b/holidays/observed_holiday_base.py index 6cc8f89c8..fd448283f 100644 --- a/holidays/observed_holiday_base.py +++ b/holidays/observed_holiday_base.py @@ -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 @@ -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) + )