Skip to content

Commit ada11d0

Browse files
authored
Merge pull request #147 from hf-kklein/default-lang
feat: Set calendar language to 'de'
2 parents 46288a1 + fd5a7e2 commit ada11d0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/bdew_datetimes/calendar.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ def create_bdew_calendar() -> HolidaySum:
5454
"""
5555

5656
# First we need the BDEW specific holidays.
57-
calendar = BdewDefinedHolidays()
57+
calendar = BdewDefinedHolidays(language="de")
5858

5959
# the type is wrong at assignment but correct after the first loop iteration
6060
result: HolidaySum = calendar # type:ignore[assignment]
61-
61+
original_language_before_adding_subdivisions = result.language
6262
# If a day is holiday in any subdivision, the holiday is valid nationwide.
6363
# Therefore, we add all subdivisions of Germany to the BDEW specific holidays.
6464
# Currently, in Germany holidays are not observed.
6565
for subdivision in Germany.subdivisions:
6666
# the method __add__ expects a Union[int, "HolidayBase", "HolidaySum"] as `other`
6767
# here, we're dealing with a child instance of HolidayBase
6868
result += Germany(
69-
subdiv=subdivision, observed=False
69+
subdiv=subdivision, observed=False, language="de"
7070
) # type:ignore[assignment]
71-
71+
if result.language is None:
72+
# This is a workaround to a problem in holidays 0.20-0.53 (at least):
73+
# When adding the subdivisions, the language attribute is lost,
74+
# although holiday base and subdivision share the same language.
75+
# The problem happens here:
76+
# https://github.com/vacanza/python-holidays/blob/v0.53/holidays/holiday_base.py#L1164
77+
result.language = original_language_before_adding_subdivisions
7278
return result

tests/test_calendar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_holiday_calendar_obj():
4646

4747
assert not calendar.observed
4848
assert calendar.country == "DE"
49+
assert calendar.language == "de"
4950

5051

5152
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)