]> git.earman.xyz Git - sensor-watch.git/commitdiff
Made the simulator properly set itself with the UTC time on startup (#7)
authorvoloved <36523934+voloved@users.noreply.github.com>
Sun, 27 Oct 2024 18:08:05 +0000 (14:08 -0400)
committerGitHub <noreply@github.com>
Sun, 27 Oct 2024 18:08:05 +0000 (14:08 -0400)
watch-library/simulator/watch/watch_rtc.c

index f99cb7bcfb1a3c2d6172fe7715339c1a1291d333..ebd41aed54beb5fc8e996c6e732d61789425866e 100644 (file)
@@ -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;
 }