From aeb18fdb701a94a51c479a5636c8e0bded62560e Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 2 Apr 2024 21:12:10 +0300 Subject: [PATCH] Refactor some sequential holidays --- holidays/countries/andorra.py | 38 ++++++++++++++++------------------ holidays/countries/botswana.py | 13 +++++------- holidays/countries/honduras.py | 7 +++---- holidays/countries/latvia.py | 9 ++++---- 4 files changed, 30 insertions(+), 37 deletions(-) diff --git a/holidays/countries/andorra.py b/holidays/countries/andorra.py index 4ecf32677..6f470c850 100644 --- a/holidays/countries/andorra.py +++ b/holidays/countries/andorra.py @@ -10,8 +10,6 @@ # Website: https://github.com/vacanza/python-holidays # License: MIT (see LICENSE file) -from datetime import timedelta as td - from holidays.groups import ChristianHolidays, InternationalHolidays from holidays.holiday_base import HolidayBase @@ -85,48 +83,48 @@ def _populate_public_holidays(self) -> None: # Canillo. def _populate_subdiv_02_public_holidays(self): name = "Canillo Annual Festival" - third_sat_of_july = self._add_holiday_3rd_sat_of_jul(name) - self._add_holiday(name, third_sat_of_july + td(days=+1)) - self._add_holiday(name, third_sat_of_july + td(days=+2)) + self._add_holiday_3rd_sat_of_jul(name) + self._add_holiday_1_day_past_3rd_sat_of_jul(name) + self._add_holiday_2_days_past_3rd_sat_of_jul(name) # Encamp. def _populate_subdiv_03_public_holidays(self): name = "Encamp Annual Festival" - aug_15 = self._add_holiday_aug_15(name) - self._add_holiday(name, aug_15 + td(days=+1)) + self._add_holiday_aug_15(name) + self._add_holiday_aug_16(name) # La Massana. def _populate_subdiv_04_public_holidays(self): name = "La Massana Annual Festival" - aug_15 = self._add_holiday_aug_15(name) - self._add_holiday(name, aug_15 + td(days=+1)) + self._add_holiday_aug_15(name) + self._add_holiday_aug_16(name) # Ordino. def _populate_subdiv_05_public_holidays(self): name = "Ordino Annual Festival" - aug_15 = self._add_holiday_aug_15(name) - self._add_holiday(name, aug_15 + td(days=+1)) + self._add_holiday_aug_15(name) + self._add_holiday_aug_16(name) # Sant Julià de Lòria. def _populate_subdiv_06_public_holidays(self): name = "Sant Julià de Lòria Annual Festival" - last_fri_of_july = self._add_holiday_1st_fri_before_jul_29(name) - self._add_holiday(name, last_fri_of_july + td(days=+1)) - self._add_holiday(name, last_fri_of_july + td(days=+2)) - self._add_holiday(name, last_fri_of_july + td(days=+3)) + self._add_holiday_1st_fri_before_jul_29(name) + self._add_holiday_1st_sat_before_jul_30(name) + self._add_holiday_1st_sun_before_jul_31(name) + self._add_holiday_1st_mon_before_aug_1(name) # Andorra la Vella. def _populate_subdiv_07_public_holidays(self): name = "Andorra la Vella Annual Festival" - first_sat_of_august = self._add_holiday_1st_sat_of_aug(name) - self._add_holiday(name, first_sat_of_august + td(days=+1)) - self._add_holiday(name, first_sat_of_august + td(days=+2)) + self._add_holiday_1st_sat_of_aug(name) + self._add_holiday_1_day_past_1st_sat_of_aug(name) + self._add_holiday_2_days_past_1st_sat_of_aug(name) # Escaldes-Engordany. def _populate_subdiv_08_public_holidays(self): name = "Escaldes-Engordany Annual Festival" - jul_25 = self._add_holiday_jul_25(name) - self._add_holiday(name, jul_25 + td(days=+1)) + self._add_holiday_jul_25(name) + self._add_holiday_jul_26(name) class AD(Andorra): diff --git a/holidays/countries/botswana.py b/holidays/countries/botswana.py index 14608544b..c40a62ed0 100644 --- a/holidays/countries/botswana.py +++ b/holidays/countries/botswana.py @@ -10,8 +10,6 @@ # Website: https://github.com/vacanza/python-holidays # License: MIT (see LICENSE file) -from datetime import timedelta as td - from holidays.calendars.gregorian import JUL from holidays.groups import ChristianHolidays, InternationalHolidays, StaticHolidays from holidays.observed_holiday_base import ObservedHolidayBase, SUN_TO_NEXT_MON, SUN_TO_NEXT_TUE @@ -56,18 +54,17 @@ def _populate_public_holidays(self): self._add_observed(self._add_holiday_jul_1("Sir Seretse Khama Day")) - third_mon_of_jul = self._add_holiday_3rd_mon_of_jul("President's Day") - self._add_holiday("President's Day Holiday", third_mon_of_jul + td(days=+1)) + self._add_holiday_3rd_mon_of_jul("President's Day") + self._add_holiday_1_day_past_3rd_mon_of_jul("President's Day Holiday") - sep_30 = self._add_holiday_sep_30("Botswana Day") - self._add_observed(sep_30, rule=SUN_TO_NEXT_TUE) - self._add_observed(self._add_holiday("Botswana Day Holiday", sep_30 + td(days=+1))) + self._add_observed(self._add_holiday_sep_30("Botswana Day"), rule=SUN_TO_NEXT_TUE) + self._add_observed(self._add_holiday_oct_1("Botswana Day Holiday")) self._add_observed(self._add_christmas_day("Christmas Day"), rule=SUN_TO_NEXT_TUE) self._add_observed(dec_26 := self._add_christmas_day_two("Boxing Day")) if self.observed and self._year >= 2016 and self._is_saturday(dec_26): - self._add_holiday("Boxing Day Holiday", dec_26 + td(days=+2)) + self._add_holiday_dec_28("Boxing Day Holiday") class BW(Botswana): diff --git a/holidays/countries/honduras.py b/holidays/countries/honduras.py index af20fb522..3edfe3237 100644 --- a/holidays/countries/honduras.py +++ b/holidays/countries/honduras.py @@ -10,7 +10,6 @@ # Website: https://github.com/vacanza/python-holidays # License: MIT (see LICENSE file) -from datetime import timedelta as td from gettext import gettext as tr from holidays.groups import ChristianHolidays, InternationalHolidays @@ -66,9 +65,9 @@ def _populate_public_holidays(self): # Morazan Weekend. name = tr("Semana Morazánica") # First Wednesday of October from 12 noon to Saturday 12 noon. - first_wed_of_oct = self._add_holiday_1st_wed_of_oct(name) - self._add_holiday(name, first_wed_of_oct + td(days=+1)) - self._add_holiday(name, first_wed_of_oct + td(days=+2)) + self._add_holiday_1st_wed_of_oct(name) + self._add_holiday_1_day_past_1st_wed_of_oct(name) + self._add_holiday_2_days_past_1st_wed_of_oct(name) # Christmas Day. self._add_christmas_day(tr("Navidad")) diff --git a/holidays/countries/latvia.py b/holidays/countries/latvia.py index 852730be8..742b2dac9 100644 --- a/holidays/countries/latvia.py +++ b/holidays/countries/latvia.py @@ -10,7 +10,6 @@ # Website: https://github.com/vacanza/python-holidays # License: MIT (see LICENSE file) -from datetime import timedelta as td from gettext import gettext as tr from holidays.calendars.gregorian import MAY, JUL, SEP @@ -68,11 +67,11 @@ def _populate_public_holidays(self): # Mother's Day. self._add_holiday_2nd_sun_of_may(tr("Mātes diena")) - # Midsummer Day. - jun_24 = self._add_saint_johns_day(tr("Jāņu diena")) - # Midsummer Eve. - self._add_holiday(tr("Līgo diena"), jun_24 + td(days=-1)) + self._add_holiday_jun_23(tr("Līgo diena")) + + # Midsummer Day. + self._add_saint_johns_day(tr("Jāņu diena")) # Republic of Latvia Proclamation Day. dt = self._add_holiday_nov_18(tr("Latvijas Republikas proklamēšanas diena"))