Skip to content

Commit

Permalink
Merge pull request #147 from hf-kklein/default-lang
Browse files Browse the repository at this point in the history
feat: Set calendar language to 'de'
  • Loading branch information
mj0nez authored Jul 23, 2024
2 parents 46288a1 + fd5a7e2 commit ada11d0
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 ada11d0

Please sign in to comment.