55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
import holidays
|
|
|
|
|
|
GERMAN_STATE_OPTIONS: list[dict[str, str]] = [
|
|
{"code": "BW", "label": "Baden-Württemberg"},
|
|
{"code": "BY", "label": "Bayern"},
|
|
{"code": "BE", "label": "Berlin"},
|
|
{"code": "BB", "label": "Brandenburg"},
|
|
{"code": "HB", "label": "Bremen"},
|
|
{"code": "HH", "label": "Hamburg"},
|
|
{"code": "HE", "label": "Hessen"},
|
|
{"code": "MV", "label": "Mecklenburg-Vorpommern"},
|
|
{"code": "NI", "label": "Niedersachsen"},
|
|
{"code": "NW", "label": "Nordrhein-Westfalen"},
|
|
{"code": "RP", "label": "Rheinland-Pfalz"},
|
|
{"code": "SL", "label": "Saarland"},
|
|
{"code": "SN", "label": "Sachsen"},
|
|
{"code": "ST", "label": "Sachsen-Anhalt"},
|
|
{"code": "SH", "label": "Schleswig-Holstein"},
|
|
{"code": "TH", "label": "Thüringen"},
|
|
]
|
|
GERMAN_STATE_CODES = {item["code"] for item in GERMAN_STATE_OPTIONS}
|
|
|
|
|
|
def normalize_german_state_code(value: str | None) -> str | None:
|
|
if value is None:
|
|
return None
|
|
normalized = value.strip().upper()
|
|
if not normalized:
|
|
return None
|
|
if normalized not in GERMAN_STATE_CODES:
|
|
return None
|
|
return normalized
|
|
|
|
|
|
def list_public_holiday_dates(
|
|
*,
|
|
federal_state: str,
|
|
from_date: date,
|
|
to_date: date,
|
|
) -> set[date]:
|
|
if to_date < from_date:
|
|
return set()
|
|
years = list(range(from_date.year, to_date.year + 1))
|
|
holiday_map = holidays.country_holidays("DE", subdiv=federal_state, years=years)
|
|
result: set[date] = set()
|
|
for holiday_date in holiday_map.keys():
|
|
if from_date <= holiday_date <= to_date:
|
|
result.add(holiday_date)
|
|
return result
|