From 94d8a581d9a01c7a52db20b0b8aa9a1bffb71c74 Mon Sep 17 00:00:00 2001 From: voloved <36523934+voloved@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:08:05 -0400 Subject: [PATCH] Made the simulator properly set itself with the UTC time on startup (#7) --- watch-library/simulator/watch/watch_rtc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index f99cb7bc..ebd41aed 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -45,6 +45,12 @@ bool _watch_rtc_is_enabled(void) { } void _watch_rtc_init(void) { + // Shifts the timezone so our local time is converted to UTC and set + int32_t time_zone_offset = EM_ASM_INT({ + return -new Date().getTimezoneOffset() * 60; + }); + watch_date_time_t date_time = watch_rtc_get_date_time(); + watch_rtc_set_date_time(watch_utility_date_time_convert_zone(date_time, time_zone_offset, 0)); } void watch_rtc_set_date_time(watch_date_time_t date_time) { @@ -62,9 +68,6 @@ void watch_rtc_set_date_time(watch_date_time_t date_time) { watch_date_time_t watch_rtc_get_date_time(void) { watch_date_time_t retval; - int32_t time_zone_offset = EM_ASM_INT({ - return -new Date().getTimezoneOffset() * 60; - }); retval.reg = EM_ASM_INT({ const date = new Date(Date.now() + $0); return date.getSeconds() | @@ -74,7 +77,6 @@ watch_date_time_t watch_rtc_get_date_time(void) { ((date.getMonth() + 1) << 22) | ((date.getFullYear() - 2020) << 26); }, time_offset); - retval = watch_utility_date_time_convert_zone(retval, time_zone_offset, 0); return retval; }