# Device timezone table Backend module `backend/timezones/` — the list of timezones that the console and the apps offer when setting a device's clock, with the rule each device needs. ## Why it exists Since firmware 3.0.0 the device RTC holds UTC and the device converts to local time itself (project-vesper `src/TimeKeeper/`, catalog F-079). In timezone mode `auto` the device is sent: ```json { "mode": "auto", "name": "Europe/Athens", "posix": "EET-2EEST,M3.5.0/3,M10.5.0/4" } ``` `posix` is a POSIX TZ rule: the standard offset, the DST offset and when DST starts/ends every year. The device evaluates it by itself, so DST switches without anyone touching the device. Devices don't carry the IANA database, so whoever sets the timezone (console, phone app, tablet app) must send the rule — and must never build it by hand (POSIX signs are inverted: `EET-2` means UTC+2). This module is where the rule comes from. ## Source of truth The pip package `tzdata` pinned in `backend/requirements.txt` (IANA release reported as `tzdata_version`): - POSIX rule = the footer line of each zone's TZif file (the same string the firmware's host tests check against CPython's `zoneinfo` for every zone — project-vesper `test/timezone/`). - Zone → country: `zone.tab`. Country names: `iso3166.tab`. Nothing is generated or committed by hand. **To pick up new DST rules** (a country changes or abolishes DST), bump the `tzdata` pin, rebuild the backend, and re-send `clock.set_timezone` to affected devices — devices keep the rule they were given until told otherwise. Re-export the tablet bundle too (below). ## Endpoints (public, no auth) Public on purpose: it is public IANA data, and the phone app (Firebase auth over MQTT) and the tablet bundle export need it without console credentials. ### `GET /api/public/timezones[?country=GR]` ```json { "tzdata_version": "2026f", "generated_at": "2026-10-28T14:05:00+00:00", "countries": [ { "code": "GR", "name": "Greece", "zones": [ { "name": "Europe/Athens", "city": "Athens", "comment": "", "posix": "EET-2EEST,M3.5.0/3,M10.5.0/4", "std_offset_min": 120, "dst_offset_min": 60, "has_dst": true, "countries": ["GR"], "current_offset_min": 120, "current_dst": false, "display": "(UTC+02:00) Athens" } ] } ] } ``` - Countries sorted by name; zones in `zone.tab` order (roughly geographic). Most countries have one zone; pick-country-then-zone UIs can skip the second step for those. - `std_offset_min` / `dst_offset_min`: minutes east of UTC; `dst_offset_min` is the DST **amount** (0 without DST, negative for Europe/Dublin, 30 for Lord Howe). Same values the device reports in `clock.get_timezone`. - `current_offset_min` / `current_dst` / `display` are computed at request time. - A zone used by several countries appears under each, with all of them in `countries`. - `country` filter: ISO 3166 alpha-2, case-insensitive. Unknown → 404. ### `GET /api/public/timezones/zone?name=Europe/Athens` One zone (same fields + `tzdata_version`). Also resolves IANA aliases that `zone.tab` doesn't list (`Asia/Calcutta`, `UTC`, …) with `countries: []` — useful for "use this phone's timezone". Unknown → 404. ## Tablet app bundle The tablet app only talks to devices over local WebSocket, often without internet, so it bundles the table: save the response of `GET /api/public/timezones` as-is (≈ 130 KB) into the app. Ignore the `current_*` and `display` fields there (they were "now" at export time) — compute the current offset on the tablet, or just show `std_offset_min`. Re-export whenever the `tzdata` pin is bumped. ## Tests `backend/tests/test_timezones.py` (pure tzdata, no Firestore/MQTT): POSIX offset parsing incl. negative, half-hour and 45-minute cases; table shape and firmware length limits (name < 48, rule < 64 chars); Greece / Australia spot checks; every zone's offset in 2030 is its standard or standard+DST offset; routes. ``` cd backend python -m pytest tests/test_timezones.py ```