From 7c50def0c92c4170b25045cd46b023809872c16e Mon Sep 17 00:00:00 2001 From: Daniel Gradman-Svendsen Date: Wed, 29 Jul 2026 20:04:37 +0200 Subject: [PATCH] Display build dates in local time --- importarr/build_info.py | 21 +++++++++++++++++++-- tests/test_status.py | 13 +++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/importarr/build_info.py b/importarr/build_info.py index db16b75..92ba64a 100644 --- a/importarr/build_info.py +++ b/importarr/build_info.py @@ -8,14 +8,31 @@ from . import __version__ def build_info() -> dict[str, str]: + build_date = os.getenv("IMPORTARR_BUILD_DATE", "development") return { "name": "Importarr", "version": os.getenv("IMPORTARR_VERSION", __version__), - "build_date": os.getenv("IMPORTARR_BUILD_DATE", "development"), + "build_date": local_timestamp(build_date), "git_sha": os.getenv("IMPORTARR_GIT_SHA", "development"), "python": platform.python_version(), "started_at": STARTED_AT, } -STARTED_AT = datetime.now(UTC).isoformat(timespec="seconds") +def local_timestamp(value: str) -> str: + if value == "development": + return value + + normalized = value.removesuffix("Z") + "+00:00" if value.endswith("Z") else value + try: + timestamp = datetime.fromisoformat(normalized) + except ValueError: + return value + + if timestamp.tzinfo is None: + timestamp = timestamp.replace(tzinfo=UTC) + + return timestamp.astimezone().isoformat(timespec="seconds") + + +STARTED_AT = datetime.now(UTC).astimezone().isoformat(timespec="seconds") diff --git a/tests/test_status.py b/tests/test_status.py index 9ac32c3..051fe33 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -8,6 +8,19 @@ def test_health_contains_build_info(tmp_path, monkeypatch): assert payload["version"] +def test_build_date_is_rendered_in_local_time(monkeypatch): + import importarr.build_info as build_info + + monkeypatch.setenv("TZ", "Europe/Copenhagen") + import time + + time.tzset() + + monkeypatch.setenv("IMPORTARR_BUILD_DATE", "2026-07-29T12:00:00Z") + + assert build_info.build_info()["build_date"] == "2026-07-29T14:00:00+02:00" + + def test_status_contains_service_configuration(tmp_path, monkeypatch): monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "state.db")) import importarr.main as main