Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set calendar language to 'de' #147

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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