feat(timezones): public IANA timezone table with POSIX rules for device clocks
Firmware 3.0.0+ (project-vesper F-079) keeps the RTC in UTC and, in timezone mode "auto", evaluates a POSIX TZ rule string sent by whoever sets the timezone. Devices don't carry the IANA database and POSIX signs are inverted, so the console and apps need one place to get the right rule. GET /api/public/timezones[?country=GR] returns every country with its zones (zone.tab), each with the POSIX rule (TZif footer), std/DST offsets in minutes east of UTC, and the current offset/DST state. GET /api/public/timezones/zone?name=... resolves one zone, including aliases zone.tab doesn't list (e.g. a phone reporting Asia/Calcutta). Public on purpose: IANA data, needed by the phone app (Firebase auth, MQTT) and for the tablet app's offline bundle (save the full response, ~130 KB). Source is the tzdata pip package, now pinned (2026.6 = IANA 2026f); bumping the pin is how new DST rules arrive. Docs in docs/device-timezones.md; tests in tests/test_timezones.py. Stage 4 of project-vesper docs/features/timekeeper-overhaul.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
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
|
||||
Reference in New Issue
Block a user