Files
bellsystems-cp/docs/device-timezones.md
bonaminandClaude Opus 5.5 e4ea43a079 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>
2026-10-28 21:01:04 +02:00

3.9 KiB

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:

{ "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]

{
  "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