Display build dates in local time
This commit is contained in:
+19
-2
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user