Made the simulator properly set itself with the UTC time on startup (#7)

This commit is contained in:
voloved 2024-10-27 14:08:05 -04:00 committed by GitHub
parent 368dd5dc2a
commit 94d8a581d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View 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;
}