M8-R11: make business timezone deterministic
frontend / frontend (push) Successful in 46s
pytest / test (push) Successful in 3m56s

This commit is contained in:
2026-08-27 12:16:52 +02:00
parent d5623b9fcb
commit 33ca3da593
6 changed files with 65 additions and 10 deletions
+33 -1
View File
@@ -7,7 +7,7 @@ on any CI host timezone.
from __future__ import annotations
from datetime import UTC, date, datetime
from zoneinfo import ZoneInfo
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
import pytest
@@ -56,6 +56,38 @@ def test_local_tz_env_var_overrides(monkeypatch):
monkeypatch.delenv("TZ")
@pytest.mark.parametrize("value", [None, "", " "])
def test_local_tz_defaults_to_dst_aware_amsterdam(monkeypatch, value: str | None):
"""Unset or blank TZ must use the deterministic Amsterdam business zone."""
if value is None:
monkeypatch.delenv("TZ", raising=False)
else:
monkeypatch.setenv("TZ", value)
tz = tz_mod.local_tz()
assert isinstance(tz, ZoneInfo)
assert tz.key == "Europe/Amsterdam"
winter = datetime(2026, 1, 15, 12, tzinfo=tz)
summer = datetime(2026, 7, 15, 12, tzinfo=tz)
assert winter.utcoffset().total_seconds() == 3600
assert summer.utcoffset().total_seconds() == 7200
def test_local_tz_explicit_utc_override(monkeypatch):
"""A non-empty TZ remains an operator-controlled override."""
monkeypatch.setenv("TZ", "UTC")
tz = tz_mod.local_tz()
assert isinstance(tz, ZoneInfo)
assert tz.key == "UTC"
def test_local_tz_invalid_explicit_override_fails_loudly(monkeypatch):
"""A non-empty invalid override must not silently become Amsterdam."""
monkeypatch.setenv("TZ", "Invalid/Timezone")
with pytest.raises(ZoneInfoNotFoundError):
tz_mod.local_tz()
# ---------------------------------------------------------------------------
# to_local() — conversion correctness
# ---------------------------------------------------------------------------