docs(api-reference): firmware 3.0.0 timezone API (clock.set_time/set_timezone/get_timezone, system.get_time)

Mirrors project-vesper F-079: the RTC holds UTC and the timezone is one
object with modes auto (POSIX rule) / manual (DST dates) / fixed / local.
clock.set_time takes timestamp (UTC) or local plus an optional timezone,
clock.get_config reports "timezone" instead of gmt_offset_sec/dst_offset_sec,
system.get_time gains local/offset_min/dst_active/tz_mode/tz_name/rtc_synced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 19:15:46 +02:00
co-authored by Claude Opus 5.5
parent 65ff2372ca
commit ca53d2e871
@@ -413,19 +413,26 @@ const NAMESPACES = [
cmd: 'clock.set_time', cmd: 'clock.set_time',
handler: 'ClockHandler', handler: 'ClockHandler',
transports: ['All'], transports: ['All'],
description: 'Set the RTC time directly. timezone_offset and dst_offset are only applied when BOTH are present (they also update the stored timezone); with only one, or neither, timestamp is written to the RTC as-is.', description: 'Set the clock (fw 3.0.0+: the RTC always holds UTC). Send exactly one of timestamp (UTC) or local (wall-clock time, converted to UTC immediately with the timezone being set, or the current one). An optional timezone object is applied in the same step; everything is validated first, so on any error nothing changes. In the repeated hour of a DST fall-back the first (DST) occurrence is used; a local time inside the spring-forward gap is moved forward by the gap.',
contents: [ contents: [
{ field: 'timestamp', type: 'int', required: true, notes: 'Unix epoch timestamp (UTC when both offsets are sent; written as-is otherwise)' }, { field: 'timestamp', type: 'int', required: false, notes: 'UTC Unix epoch seconds (2024..2099). Exactly one of timestamp / local.' },
{ field: 'timezone_offset', type: 'int', required: false, notes: 'Total UTC offset in seconds incl. DST (e.g. 10800 for UTC+2 with DST). Ignored unless dst_offset is also sent.' }, { field: 'local', type: 'string', required: false, notes: 'Local wall-clock time "YYYY-MM-DDTHH:MM:SS" (a space instead of T is accepted). Exactly one of timestamp / local. With timezone mode local this IS the device time (offset 0).' },
{ field: 'dst_offset', type: 'int', required: false, notes: 'DST offset in seconds. Ignored unless timezone_offset is also sent.' }, { field: 'timezone', type: 'object', required: false, notes: 'Timezone object. mode auto: posix (required) + name. mode manual: std_offset_min, dst_offset_min, dst_start, dst_end (all required) + name. mode fixed: std_offset_min (required), dst_offset_min (default 0) + name. mode local: no other fields. Same validation and errors as clock.set_timezone.' },
], ],
response: '{ "status": "SUCCESS", "type": "clock.set_time", "message": "RTC time updated successfully" }', response: '{\n "status": "SUCCESS",\n "type": "clock.set_time",\n "data": {\n "rtc_available": true, "rtc_synced": true,\n "utc_timestamp": 1793196300, "local_timestamp": 1793203500,\n "local": "2026-10-28T16:05:00",\n "offset_min": 120, "dst_active": false,\n "tz_mode": "auto", "tz_name": "Europe/Athens",\n "year": 2026, "month": 10, "day": 28, "hour": 16, "minute": 5, "second": 0, "weekday": 3\n }\n}',
errors: [ errors: [
{ message: 'Missing required field: timestamp', condition: 'contents.timestamp is absent' }, { message: 'Provide exactly one of: timestamp (UTC epoch) or local', condition: 'Both or neither present' },
{ message: 'Invalid timestamp value', condition: 'timestamp is 0' }, { message: 'Invalid local time (expected YYYY-MM-DDTHH:MM:SS)', condition: 'Malformed or impossible date (e.g. Feb 29 in a non-leap year), year outside 2000..2099' },
{ message: 'RTC time set but verification failed', condition: 'RTC read-back returned 0 after the write — hardware issue' }, { message: 'Time out of range (2024..2099)', condition: 'Resulting UTC before 2024-01-01 or after 2099' },
{ message: 'RTC write failed (read-back mismatch)', condition: 'RTC did not hold the written value (hardware fault)' },
{ message: 'Missing required field: mode', condition: 'mode absent' },
{ message: 'Invalid mode (expected auto, manual, fixed or local)', condition: 'mode is not one of the four values (lowercase)' },
{ message: 'Missing required field: posix', condition: 'mode auto without posix' },
{ message: 'Missing required fields for manual: std_offset_min, dst_offset_min, dst_start, dst_end', condition: 'mode manual with any of them missing' },
{ message: 'Missing required field: std_offset_min', condition: 'mode fixed without std_offset_min' },
{ message: 'Invalid timezone: <reason>', condition: 'Reasons: posix is not a valid POSIX TZ rule | posix too long | name too long | std_offset_min out of range (-720..840) | dst_offset_min must be non-zero, -180..180 | dst_offset_min out of range (-180..180) | dst_end must be after dst_start | dst_start..dst_end spans more than one season' },
], ],
example: '{\n "v": 2,\n "cmd": "clock.set_time",\n "contents": { "timestamp": 1740000000, "timezone_offset": 7200, "dst_offset": 3600 }\n}', example: '{\n "v": 2,\n "cmd": "clock.set_time",\n "contents": { "timestamp": 1793145600 }\n}\n\n{\n "v": 2,\n "cmd": "clock.set_time",\n "contents": {\n "local": "2026-10-28T14:05:00",\n "timezone": { "mode": "fixed", "name": "Site time", "std_offset_min": 120, "dst_offset_min": 0 }\n }\n}\n\n{\n "v": 2,\n "cmd": "clock.set_time",\n "contents": { "local": "2026-10-28T14:05:00", "timezone": { "mode": "local" } }\n}',
warning: null, warning: null,
}, },
{ {
@@ -451,26 +458,35 @@ const NAMESPACES = [
cmd: 'clock.set_timezone', cmd: 'clock.set_timezone',
handler: 'ClockHandler', handler: 'ClockHandler',
transports: ['All'], transports: ['All'],
description: 'Set timezone independently of RTC time. Does not alter the stored time value — only changes how it is displayed/offset.', description: 'Set the timezone (fw 3.0.0+). The RTC (UTC) is not touched; only the UTC to local conversion changes, so the physical clock, alerts and events follow immediately. Modes: auto = IANA zone + POSIX rule, DST switches every year by itself (the normal case; take the rule from the backend timezone table, never build it by hand: POSIX signs are inverted, EET-2 means UTC+2). manual = std offset + one DST amount active between dst_start and dst_end (one season, re-enter yearly). fixed = constant offsets, never switch. local = offset 0, the device keeps local time as if it were UTC. Offsets are minutes EAST of UTC (UTC+2 = 120, India = 330).',
contents: [ contents: [
{ field: 'gmt_offset_sec', type: 'int', required: true, notes: 'GMT offset in seconds (e.g. 7200 for UTC+2)' }, { field: 'mode', type: 'string', required: true, notes: 'auto | manual | fixed | local (lowercase)' },
{ field: 'dst_offset_sec', type: 'int', required: false, notes: 'DST offset in seconds (e.g. 3600)' }, { field: 'name', type: 'string', required: false, notes: 'Display name, max 47 chars. For auto use the IANA name, e.g. "Europe/Athens". Forced to "Local" in mode local.' },
{ field: 'posix', type: 'string', required: false, notes: 'auto only, required there. POSIX TZ rule, max 63 chars, e.g. "EET-2EEST,M3.5.0/3,M10.5.0/4". DST zones must include start/end rules.' },
{ field: 'std_offset_min', type: 'int', required: false, notes: 'manual + fixed (required there). Standard offset in minutes east of UTC, -720..840.' },
{ field: 'dst_offset_min', type: 'int', required: false, notes: 'manual: DST amount, required, non-zero, -180..180 (usually 60). fixed: current DST offset, optional, default 0.' },
{ field: 'dst_start', type: 'int', required: false, notes: 'manual only, required. UTC epoch when DST starts.' },
{ field: 'dst_end', type: 'int', required: false, notes: 'manual only, required. UTC epoch when DST ends; after dst_start, at most ~400 days later.' },
], ],
response: '{ "status": "SUCCESS", "type": "clock.set_timezone", "message": "Timezone updated and saved" }', response: '{\n "status": "SUCCESS",\n "type": "clock.set_timezone",\n "data": {\n "mode": "auto", "name": "Europe/Athens",\n "posix": "EET-2EEST,M3.5.0/3,M10.5.0/4",\n "std_offset_min": 120, "dst_offset_min": 60,\n "dst_start": 0, "dst_end": 0,\n "current_offset_min": 120, "dst_active": false,\n "next_transition": 1806195600, "dst_schedule_expired": false\n }\n}',
errors: [ errors: [
{ message: 'Missing required field: gmt_offset_sec', condition: 'contents.gmt_offset_sec is absent' }, { message: 'Missing required field: mode', condition: 'mode absent' },
{ message: 'Timezone updated but failed to save to SD', condition: 'SD card write failed' }, { message: 'Invalid mode (expected auto, manual, fixed or local)', condition: 'mode is not one of the four values (lowercase)' },
{ message: 'Missing required field: posix', condition: 'mode auto without posix' },
{ message: 'Missing required fields for manual: std_offset_min, dst_offset_min, dst_start, dst_end', condition: 'mode manual with any of them missing' },
{ message: 'Missing required field: std_offset_min', condition: 'mode fixed without std_offset_min' },
{ message: 'Invalid timezone: <reason>', condition: 'Reasons: posix is not a valid POSIX TZ rule | posix too long | name too long | std_offset_min out of range (-720..840) | dst_offset_min must be non-zero, -180..180 | dst_offset_min out of range (-180..180) | dst_end must be after dst_start | dst_start..dst_end spans more than one season' },
], ],
example: '{ "v": 2, "cmd": "clock.set_timezone", "contents": { "gmt_offset_sec": 7200, "dst_offset_sec": 3600 } }', example: '{\n "v": 2,\n "cmd": "clock.set_timezone",\n "contents": { "mode": "auto", "name": "Australia/Sydney", "posix": "AEST-10AEDT,M10.1.0,M4.1.0/3" }\n}\n\n{\n "v": 2,\n "cmd": "clock.set_timezone",\n "contents": {\n "mode": "manual", "name": "Custom",\n "std_offset_min": 120, "dst_offset_min": 60,\n "dst_start": 1774746000, "dst_end": 1792890000\n }\n}\n\n{ "v": 2, "cmd": "clock.set_timezone", "contents": { "mode": "fixed", "std_offset_min": 330 } }',
warning: null, warning: null,
}, },
{ {
cmd: 'clock.get_timezone', cmd: 'clock.get_timezone',
handler: 'ClockHandler', handler: 'ClockHandler',
transports: ['All'], transports: ['All'],
description: 'Read current timezone settings.', description: 'Read the timezone and its live state. All fields are always present (unused ones are 0 or ""). In auto, std_offset_min / dst_offset_min are derived from the rule. next_transition = UTC epoch of the next offset change (0 if none known). dst_schedule_expired is true only in manual once dst_end has passed (ask the user for next year\'s dates).',
contents: null, contents: null,
response: '{\n "status": "SUCCESS",\n "type": "clock.get_timezone",\n "data": {\n "gmt_offset_sec": 7200,\n "dst_offset_sec": 3600,\n "ntp_server": "pool.ntp.org"\n }\n}', response: '{\n "status": "SUCCESS",\n "type": "clock.get_timezone",\n "data": {\n "mode": "auto", "name": "Europe/Athens",\n "posix": "EET-2EEST,M3.5.0/3,M10.5.0/4",\n "std_offset_min": 120, "dst_offset_min": 60,\n "dst_start": 0, "dst_end": 0,\n "current_offset_min": 120, "dst_active": false,\n "next_transition": 1806195600, "dst_schedule_expired": false\n }\n}',
errors: [], errors: [],
example: '{ "v": 2, "cmd": "clock.get_timezone" }', example: '{ "v": 2, "cmd": "clock.get_timezone" }',
warning: null, warning: null,
@@ -549,9 +565,9 @@ const NAMESPACES = [
cmd: 'clock.get_config', cmd: 'clock.get_config',
handler: 'ClockHandler', handler: 'ClockHandler',
transports: ['All'], transports: ['All'],
description: 'Read full clock configuration — outputs, timings, alerts, backlight, silence, enabled state, and timezone. Supersedes clock.get_timezone.', description: 'Read full clock configuration — outputs, timings, alerts, backlight, silence, enabled state, NTP server and timezone (the timezone field is the clock.get_timezone object; fw 3.0.0 replaced gmt_offset_sec / dst_offset_sec).',
contents: null, contents: null,
response: '{\n "status": "SUCCESS",\n "type": "clock.get_config",\n "data": {\n "enabled": true,\n "c1output": 4, "c2output": 5,\n "pulse_duration": 100, "pause_duration": 500,\n "physical_hour": 10, "physical_minute": 30,\n "next_is_c1": true, "last_sync_time": 1740000000,\n "alert_type": "HOURS", "alert_interval": 1,\n "hour_bell": 5, "half_bell": 255, "quarter_bell": 255,\n "backlight": true, "backlight_output": 6,\n "backlight_on": "07:00", "backlight_off": "22:00",\n "daytime_silence": false, "daytime_on": "00:00", "daytime_off": "00:00",\n "night_silence": true, "night_on": "22:00", "night_off": "07:00",\n "gmt_offset_sec": 7200, "dst_offset_sec": 3600, "ntp_server": "pool.ntp.org"\n }\n}', response: '{\n "status": "SUCCESS",\n "type": "clock.get_config",\n "data": {\n "enabled": true,\n "c1output": 4, "c2output": 5,\n "pulse_duration": 100, "pause_duration": 500,\n "physical_hour": 10, "physical_minute": 30,\n "next_is_c1": true, "last_sync_time": 1740000000,\n "alert_type": "HOURS", "alert_interval": 1,\n "hour_bell": 5, "half_bell": 255, "quarter_bell": 255,\n "backlight": true, "backlight_output": 6,\n "backlight_on": "07:00", "backlight_off": "22:00",\n "daytime_silence": false, "daytime_on": "00:00", "daytime_off": "00:00",\n "night_silence": true, "night_on": "22:00", "night_off": "07:00",\n "timezone": { ...same object as clock.get_timezone... },\n "ntp_server": "pool.ntp.org"\n }\n}',
errors: [], errors: [],
example: '{ "v": 2, "cmd": "clock.get_config" }', example: '{ "v": 2, "cmd": "clock.get_config" }',
warning: null, warning: null,
@@ -604,9 +620,9 @@ const NAMESPACES = [
cmd: 'system.get_time', cmd: 'system.get_time',
handler: 'SystemHandler', handler: 'SystemHandler',
transports: ['All'], transports: ['All'],
description: 'Get current RTC time in local and UTC, plus individual date/time fields.', description: 'Current time. utc_timestamp is the real instant (the RTC holds UTC since fw 3.0.0). year..second and weekday (0 = Sunday) are LOCAL time; local is the same as an ISO string. local_timestamp is local wall-clock time written as an epoch (UTC + offset), not a real instant. rtc_synced is false until NTP or clock.set_time has written the RTC with fw 3.0.0+ (e.g. right after updating from 2.x).',
contents: null, contents: null,
response: '{\n "status": "SUCCESS",\n "type": "system.get_time",\n "data": {\n "local_timestamp": 1740000000,\n "utc_timestamp": 1739993000,\n "rtc_available": true,\n "year": 2025, "month": 2, "day": 20,\n "hour": 10, "minute": 30, "second": 0\n }\n}', response: '{\n "status": "SUCCESS",\n "type": "system.get_time",\n "data": {\n "rtc_available": true, "rtc_synced": true,\n "utc_timestamp": 1793196300, "local_timestamp": 1793203500,\n "local": "2026-10-28T16:05:00",\n "offset_min": 120, "dst_active": false,\n "tz_mode": "auto", "tz_name": "Europe/Athens",\n "year": 2026, "month": 10, "day": 28, "hour": 16, "minute": 5, "second": 0, "weekday": 3\n }\n}',
errors: [], errors: [],
example: '{ "v": 2, "cmd": "system.get_time" }', example: '{ "v": 2, "cmd": "system.get_time" }',
warning: null, warning: null,