Skip to content

Commit

Permalink
Refactor Isle of Man holidays (Tynwald Day) (#1532)
Browse files Browse the repository at this point in the history
Co-authored-by: Arkadii Yakovets <ark@cho.red>
  • Loading branch information
KJhellico and arkid15r committed Oct 26, 2023
1 parent 7d737a9 commit 142cbcc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 5 additions & 5 deletions holidays/countries/isle_of_man.py
Expand Up @@ -10,7 +10,6 @@
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td

from holidays.calendars.gregorian import JUL
from holidays.countries.united_kingdom import UnitedKingdom, UnitedKingdomStaticHolidays
Expand All @@ -28,7 +27,8 @@ def __init__(self, *args, **kwargs): # Override UnitedKingdom __init__().
ChristianHolidays.__init__(self)
InternationalHolidays.__init__(self)
StaticHolidays.__init__(self, UnitedKingdomStaticHolidays)
ObservedHolidayBase.__init__(self, observed_rule=SAT_SUN_TO_NEXT_MON, *args, **kwargs)
kwargs.setdefault("observed_rule", SAT_SUN_TO_NEXT_MON)
ObservedHolidayBase.__init__(self, *args, **kwargs)

def _populate(self, year: int) -> None:
super()._populate(year)
Expand All @@ -47,9 +47,9 @@ def _populate(self, year: int) -> None:
# Tynwald Day
# Move to the next Monday if falls on a weekend.
dt = date(year, JUL, 5)
if self._is_weekend(dt) and year >= 1992:
dt += td(days=+2 if self._is_saturday(dt) else +1)
self._add_holiday("Tynwald Day", dt)
self._add_holiday(
"Tynwald Day", self._get_observed_date(dt, SAT_SUN_TO_NEXT_MON) if year >= 1992 else dt
)


class IM(IsleOfMan):
Expand Down
5 changes: 1 addition & 4 deletions tests/countries/test_isle_of_man.py
Expand Up @@ -42,10 +42,7 @@ def test_2022(self):
("2022-04-18", "Easter Monday"),
("2022-05-02", "May Day"),
("2022-06-02", "Spring Bank Holiday"),
(
"2022-06-03",
"Platinum Jubilee of Elizabeth II; TT Bank Holiday",
),
("2022-06-03", "Platinum Jubilee of Elizabeth II; TT Bank Holiday"),
("2022-07-05", "Tynwald Day"),
("2022-08-29", "Late Summer Bank Holiday"),
("2022-09-19", "State Funeral of Queen Elizabeth II"),
Expand Down

0 comments on commit 142cbcc

Please sign in to comment.