""" Public (no-auth) timezone table for device clock setup — see timezones/service.py. Public on purpose: it is IANA data, and the phone app (Firebase auth, MQTT) and the tablet bundle export both need it without console credentials. """ from fastapi import APIRouter, HTTPException, Query from timezones import service router = APIRouter(prefix="/api/public/timezones", tags=["timezones"]) @router.get("") async def list_timezones(country: str | None = Query(None, description="ISO 3166 alpha-2 code, e.g. GR")): """All countries with their IANA zones, POSIX rules and current offsets. The response is also the file the tablet app bundles (save it as-is; `tzdata_version` tells which IANA release it came from). """ table = service.get_table(country) if table is None: raise HTTPException(status_code=404, detail=f"Unknown country code: {country}") return table @router.get("/zone") async def get_timezone(name: str = Query(..., description="IANA zone name, e.g. Europe/Athens")): """One zone by IANA name — e.g. to turn a phone's own timezone into a device rule.""" zone = service.get_zone(name) if zone is None: raise HTTPException(status_code=404, detail=f"Unknown timezone: {name}") return zone