check_and_act_on_daylight_savings now only occurs in one spot

This commit is contained in:
David Volovskiy 2024-08-04 10:11:33 -04:00
parent 2824a62908
commit 598e876186
7 changed files with 36 additions and 33 deletions

View file

@ -247,6 +247,31 @@ static inline void _movement_disable_fast_tick_if_possible(void) {
}
}
static bool _check_and_act_on_daylight_savings(void) {
if (!movement_state.settings.bit.dst_active) return false;
watch_date_time date_time = watch_rtc_get_date_time();
// No need for all of the unix time calculations for times not at the beginning or end of the hour
if (date_time.unit.minute > 1 && date_time.unit.minute < 59) return false;
uint8_t dst_result = get_dst_status(date_time);
bool dst_skip_rolling_back = get_dst_skip_rolling_back();
if (dst_skip_rolling_back && (dst_result == DST_ENDED)) {
clear_dst_skip_rolling_back();
}
else if (dst_result == DST_ENDING && !dst_skip_rolling_back) {
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
watch_rtc_set_date_time(date_time);
set_dst_skip_rolling_back();
return true;
}
else if (dst_result == DST_STARTING) {
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
watch_rtc_set_date_time(date_time);
return true;
}
return false;
}
static void _movement_handle_background_tasks(void) {
for(uint8_t i = 0; i < MOVEMENT_NUM_FACES; i++) {
// For each face, if the watch face wants a background task...
@ -256,6 +281,7 @@ static void _movement_handle_background_tasks(void) {
watch_faces[i].loop(background_event, &movement_state.settings, watch_face_contexts[i]);
}
}
_check_and_act_on_daylight_savings();
movement_state.needs_background_tasks_handled = false;
}
@ -430,28 +456,6 @@ uint8_t movement_claim_backup_register(void) {
return movement_state.next_available_backup_register++;
}
bool check_and_act_on_daylight_savings(watch_date_time date_time) {
if (!movement_state.settings.bit.dst_active) return false;
uint8_t dst_result = get_dst_status(date_time);
bool dst_skip_rolling_back = get_dst_skip_rolling_back();
if (dst_skip_rolling_back && (dst_result == DST_ENDED)) {
clear_dst_skip_rolling_back();
}
else if (dst_result == DST_ENDING && !dst_skip_rolling_back) {
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
watch_rtc_set_date_time(date_time);
set_dst_skip_rolling_back();
return true;
}
else if (dst_result == DST_STARTING) {
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
watch_rtc_set_date_time(date_time);
return true;
}
return false;
}
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time) {
if (!movement_state.settings.bit.dst_active) return movement_timezone_offsets[timezone_idx];
if (dst_occurring(date_time))

View file

@ -313,7 +313,6 @@ void movement_play_alarm(void);
void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
uint8_t movement_claim_backup_register(void);
bool check_and_act_on_daylight_savings(watch_date_time date_time); // Returns if the time was changed due to DST
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time);
#endif // MOVEMENT_H_

View file

@ -283,9 +283,9 @@ void clock_face_resign(movement_settings_t *settings, void *context) {
bool clock_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
clock_state_t *state = (clock_state_t *) context;
watch_date_time date_time = watch_rtc_get_date_time();
check_and_act_on_daylight_savings(date_time);
if (!state->time_signal_enabled) return false;
watch_date_time date_time = watch_rtc_get_date_time();
return date_time.unit.minute == 0;
}

View file

@ -230,9 +230,9 @@ void minute_repeater_decimal_face_resign(movement_settings_t *settings, void *co
bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
minute_repeater_decimal_state_t *state = (minute_repeater_decimal_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();
check_and_act_on_daylight_savings(date_time);
if (!state->signal_enabled) return false;
watch_date_time date_time = watch_rtc_get_date_time();
return date_time.unit.minute == 0;
}

View file

@ -213,9 +213,9 @@ void repetition_minute_face_resign(movement_settings_t *settings, void *context)
bool repetition_minute_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
repetition_minute_state_t *state = (repetition_minute_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();
check_and_act_on_daylight_savings(date_time);
if (!state->signal_enabled) return false;
watch_date_time date_time = watch_rtc_get_date_time();
return date_time.unit.minute == 0;
}

View file

@ -214,9 +214,9 @@ void simple_clock_bin_led_face_resign(movement_settings_t *settings, void *conte
bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
simple_clock_bin_led_state_t *state = (simple_clock_bin_led_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();
check_and_act_on_daylight_savings(date_time);
if (!state->signal_enabled) return false;
watch_date_time date_time = watch_rtc_get_date_time();
return date_time.unit.minute == 0;
}

View file

@ -153,9 +153,9 @@ void simple_clock_face_resign(movement_settings_t *settings, void *context) {
bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
simple_clock_state_t *state = (simple_clock_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();
check_and_act_on_daylight_savings(date_time);
if (!state->signal_enabled) return false;
watch_date_time date_time = watch_rtc_get_date_time();
return date_time.unit.minute == 0;
}