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

Refactor some sequential holidays #1750

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions holidays/countries/andorra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
13 changes: 5 additions & 8 deletions holidays/countries/botswana.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions holidays/countries/honduras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
9 changes: 4 additions & 5 deletions holidays/countries/latvia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down