Skip to content

Commit

Permalink
Add categories support to subdivision holidays methods (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico committed Aug 29, 2023
1 parent aa3fd1b commit 2ab20c5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions holidays/holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,19 @@ def _add_holiday(self, name: str, *args) -> Optional[date]:
self[dt] = self.tr(name)
return dt

def _add_subdiv_holidays(self):
"""Populate subdivision holidays."""
def _add_subdiv_category_holidays(self, category: str = None):
"""Populate subdivision holidays by category."""
if self.subdiv is not None:
subdiv = self.subdiv.replace("-", "_").replace(" ", "_").lower()
add_subdiv_holidays = getattr(self, f"_add_subdiv_{subdiv}_holidays", None)
method_name = f"_add_subdiv_{subdiv}{f'_{category}' if category else ''}_holidays"
add_subdiv_holidays = getattr(self, method_name, None)
if add_subdiv_holidays and callable(add_subdiv_holidays):
add_subdiv_holidays()

def _add_subdiv_holidays(self):
"""Populate subdivision holidays."""
self._add_subdiv_category_holidays()

def _add_substituted_holidays(self):
"""Populate substituted holidays."""
if len(self.substituted_holidays) == 0:
Expand Down Expand Up @@ -758,6 +763,9 @@ def _populate_categories(self):
if populate_category_holidays and callable(populate_category_holidays):
populate_category_holidays()

# Populate subdivision holidays for all categories.
self._add_subdiv_category_holidays(category)

def append(self, *args: Union[Dict[DateLike, str], List[DateLike], DateLike]) -> None:
"""Alias for :meth:`update` to mimic list type."""
return self.update(*args)
Expand Down

0 comments on commit 2ab20c5

Please sign in to comment.