diff --git a/watch-faces/complication/deadline_face.c b/watch-faces/complication/deadline_face.c index ebad0e8b..a7e0aee7 100644 --- a/watch-faces/complication/deadline_face.c +++ b/watch-faces/complication/deadline_face.c @@ -227,8 +227,6 @@ static void _correct_time_difference(int16_t *units, watch_date_time_t deadline) /* Increment date in settings mode. Function taken from `set_time_face.c` */ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time) { - const uint8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31 }; - switch (state->current_page) { case 0: /* Only 10 years covered. Fix this sometime next decade */ @@ -237,17 +235,15 @@ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time case 1: date_time.unit.month = (date_time.unit.month % 12) + 1; break; - case 2: - date_time.unit.day = date_time.unit.day + 1; + case 2: { + int days = _days_in_month(date_time.unit.month, date_time.unit.year); - /* Check for leap years */ - int8_t days = days_in_month[date_time.unit.month - 1]; - if (date_time.unit.month == 2 && _is_leap(date_time.unit.year)) - days++; - - if (date_time.unit.day > days) - date_time.unit.day = 1; + /* Compute next day outside the 5-bit bitfield so overflow past 31 + * can be compared against `days` before it gets truncated. */ + uint8_t day = date_time.unit.day + 1; + date_time.unit.day = (day > days) ? 1 : day; break; + } case 3: date_time.unit.hour = (date_time.unit.hour + 1) % 24; break;