diff --git a/movement.c b/movement.c index ee8f6cc6..28aec82f 100644 --- a/movement.c +++ b/movement.c @@ -557,19 +557,6 @@ void app_init(void) { _movement_reset_inactivity_countdown(); filesystem_init(); - -#if __EMSCRIPTEN__ - /// FIXME: for #SecondMovement: Figure out how to set the time zone automatically! This method no longer works. - // int32_t time_zone_offset = EM_ASM_INT({ - // return -new Date().getTimezoneOffset(); - // }); - // for (int i = 0, count = sizeof(movement_timezone_offsets) / sizeof(movement_timezone_offsets[0]); i < count; i++) { - // if (movement_timezone_offsets[i] == time_zone_offset) { - // movement_state.settings.bit.time_zone = i; - // break; - // } - // } -#endif } void app_wake_from_backup(void) { @@ -595,6 +582,18 @@ void app_setup(void) { // populate the DST offset cache _movement_update_dst_offset_cache(); +#if __EMSCRIPTEN__ + int32_t time_zone_offset = EM_ASM_INT({ + return -new Date().getTimezoneOffset(); + }); + for (int i = 0; i < NUM_ZONE_NAMES; i++) { + if (movement_get_current_timezone_offset_for_zone(i) == time_zone_offset * 60) { + movement_state.settings.bit.time_zone = i; + break; + } + } +#endif + // set up the 1 minute alarm (for background tasks and low power updates) watch_date_time_t alarm_time; alarm_time.reg = 0; diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index 852bf16e..f99cb7bc 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -24,6 +24,7 @@ #include "watch_rtc.h" #include "watch_main_loop.h" +#include "watch_utility.h" #include #include @@ -61,6 +62,9 @@ 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() | @@ -70,6 +74,7 @@ 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; }