Skip to content

Commit

Permalink
feat: Set calendar language to 'de'
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein committed Jul 22, 2024
1 parent 4f04406 commit fd5a7e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/bdew_datetimes/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,25 @@ def create_bdew_calendar() -> HolidaySum:
"""

# First we need the BDEW specific holidays.
calendar = BdewDefinedHolidays()
calendar = BdewDefinedHolidays(language="de")

# the type is wrong at assignment but correct after the first loop iteration
result: HolidaySum = calendar # type:ignore[assignment]

original_language_before_adding_subdivisions = result.language
# If a day is holiday in any subdivision, the holiday is valid nationwide.
# Therefore, we add all subdivisions of Germany to the BDEW specific holidays.
# Currently, in Germany holidays are not observed.
for subdivision in Germany.subdivisions:
# the method __add__ expects a Union[int, "HolidayBase", "HolidaySum"] as `other`
# here, we're dealing with a child instance of HolidayBase
result += Germany(
subdiv=subdivision, observed=False
subdiv=subdivision, observed=False, language="de"
) # type:ignore[assignment]

if result.language is None:
# This is a workaround to a problem in holidays 0.20-0.53 (at least):
# When adding the subdivisions, the language attribute is lost,
# although holiday base and subdivision share the same language.
# The problem happens here:
# https://github.com/vacanza/python-holidays/blob/v0.53/holidays/holiday_base.py#L1164
result.language = original_language_before_adding_subdivisions
return result
1 change: 1 addition & 0 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_holiday_calendar_obj():

assert not calendar.observed
assert calendar.country == "DE"
assert calendar.language == "de"


@pytest.mark.parametrize(
Expand Down

0 comments on commit fd5a7e2

Please sign in to comment.