Skip to content

Commit

Permalink
fix time zones in simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Oct 7, 2024
1 parent a988733 commit ab861d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
25 changes: 12 additions & 13 deletions movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions watch-library/simulator/watch/watch_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "watch_rtc.h"
#include "watch_main_loop.h"
#include "watch_utility.h"

#include <emscripten.h>
#include <emscripten/html5.h>
Expand Down Expand Up @@ -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() |
Expand All @@ -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;
}

Expand Down

0 comments on commit ab861d8

Please sign in to comment.