Skip to content

Commit

Permalink
Made the simulator properly set itself with the UTC time on startup (j…
Browse files Browse the repository at this point in the history
  • Loading branch information
voloved authored Oct 27, 2024
1 parent 368dd5d commit 94d8a58
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions watch-library/simulator/watch/watch_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() |
Expand All @@ -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;
}

Expand Down

0 comments on commit 94d8a58

Please sign in to comment.