Made the days_in_month its own function

This commit is contained in:
David Volovskiy
2024-08-10 07:40:52 -04:00
parent 6ae5dfef70
commit 09576807eb
7 changed files with 21 additions and 13 deletions

View File

@@ -28,8 +28,6 @@
#include "watch.h"
#include "watch_utility.h"
static const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static uint32_t _day_one_face_juliandaynum(uint16_t year, uint16_t month, uint16_t day) {
// from here: https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation
return (1461 * (year + 4800 + (month - 14) / 12)) / 4 + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 - (3 * ((year + 4900 + (month - 14) / 12) / 100))/4 + day - 32075;
@@ -71,7 +69,7 @@ static void _day_one_face_increment(day_one_state_t *state) {
default:
break;
}
if (state->birth_day == 0 || state->birth_day > (days_in_month[state->birth_month - 1] + (is_leap(state->birth_year) && state->birth_month == 2)))
if (state->birth_day == 0 || state->birth_day > days_in_month(state->birth_month, state->birth_year))
state->birth_day = 1;
}

View File

@@ -159,7 +159,6 @@ static void _draw(time_left_state_t *state, uint8_t subsecond) {
/// @brief handle short or long pressing the alarm button
static void _handle_alarm_button(time_left_state_t *state) {
const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
switch (state->current_page) {
case TIME_LEFT_FACE_SETTINGS_STATE: // birth year
state->birth_date.bit.year++;
@@ -182,9 +181,9 @@ static void _handle_alarm_button(time_left_state_t *state) {
state->target_date.bit.day++;
break;
}
if (state->birth_date.bit.day > (days_in_month[state->birth_date.bit.month - 1] + (is_leap(state->birth_date.bit.year) && state->birth_date.bit.month == 2)))
if (state->birth_date.bit.day > days_in_month(state->birth_date.bit.month, state->birth_date.bit.year))
state->birth_date.bit.day = 1;
if (state->target_date.bit.day > (days_in_month[state->target_date.bit.month - 1] + (is_leap(state->target_date.bit.year) && state->target_date.bit.month == 2)))
if (state->target_date.bit.day > days_in_month(state->target_date.bit.month, state->birth_date.bit.year))
state->target_date.bit.day = 1;
}