fix(sim): add sim_test_set_timezone_hours() -- clock was showing UTC

NodePrefs::tz_offset_hours defaults to 0 (UTC) -- correct for real
hardware, which has no other way to know the visitor's timezone besides
Settings > System > Timezone. SimRTCClock (see 718dbdbe) is already
correct live UTC (time(NULL)), but without a timezone applied, a demo
instance's Clock screen displayed correct-but-UTC time, which just reads
as "wrong" to a visitor who never opened Settings -- e.g. 20:40 shown
while it was really 22:40 CEST. This is the other half of the site's
"would be nice if the time was synced with the computer" ask; 718dbdbe
only fixed the stale-IDBFS-restore half.

sim_test_set_timezone_hours(int) is a new sim-only hook, same shape as
sim_test_show_all_home_pages(): meshcore-solo-site calls it once after
boot with the browser's own timezone offset. Whole hours only
(tz_offset_hours is an int8_t) -- same limit a real device's own
Settings field has.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018iubftDmKNWmkNnhJRz8UH
This commit is contained in:
Jakub
2026-09-03 22:42:44 +02:00
co-authored by Claude Sonnet 5
parent c3ce3f1606
commit f10a1e7b4f
+20
View File
@@ -446,6 +446,26 @@ extern "C" EMSCRIPTEN_KEEPALIVE int sim_test_show_all_home_pages() {
return 1;
}
// tz_offset_hours (NodePrefs.h) defaults to 0 (UTC) -- real hardware has
// no other way to know the visitor's timezone, so a real user sets it
// manually in Settings > System > Timezone. RTCClock itself (SimRTCClock.h)
// is already correct live UTC (time(NULL)), so a demo instance's Clock
// screen otherwise displays correct-but-UTC time, which reads as "wrong"
// to a visitor who never opened Settings -- exactly the site's own
// "would be nice if the time was synced with the computer" ask. Called
// once after boot with the browser's own timezone offset (whole hours
// only -- tz_offset_hours is an int8_t, same real-hardware constraint a
// half-hour-offset timezone would hit too).
extern "C" EMSCRIPTEN_KEEPALIVE int sim_test_set_timezone_hours(int hours) {
if (!g_sim_ready) return 0;
NodePrefs* prefs = the_mesh.getNodePrefs();
if (!prefs) return 0;
if (hours < -12) hours = -12;
if (hours > 14) hours = 14;
prefs->tz_offset_hours = (int8_t)hours;
return 1;
}
#ifdef DISPLAY_CLASS
// Jumps the on-device UI straight to the DM thread with the first known
// ADV_TYPE_CHAT contact (UITask::openContactDM() -- the exact same real