Skip to content

Instantly share code, notes, and snippets.

@TrueBrain
Created August 16, 2023 14:36
Show Gist options
  • Save TrueBrain/6a5eeb9d809178d21ab7cab933caa4e2 to your computer and use it in GitHub Desktop.
Save TrueBrain/6a5eeb9d809178d21ab7cab933caa4e2 to your computer and use it in GitHub Desktop.
diff --git a/src/timer/timer_game_calendar.h b/src/timer/timer_game_calendar.h
index de8c78a8ec..7c9763300d 100644
--- a/src/timer/timer_game_calendar.h
+++ b/src/timer/timer_game_calendar.h
@@ -109,6 +109,19 @@ public:
static Month month; ///< Current month (0..11).
static Date date; ///< Current date in days (day counter).
static DateFract date_fract; ///< Fractional part of the day.
+
+ static const int DAYS_IN_YEAR = 365;
+ static constexpr Year ORIGINAL_BASE_YEAR = 1920;
+ static constexpr Date DateAtStartOfYear(Year year)
+ {
+ int32_t year_as_int = static_cast<int32_t>(year);
+ uint number_of_leap_years = (year == 0) ? 0 : ((year_as_int - 1) / 4 - (year_as_int - 1) / 100 + (year_as_int - 1) / 400 + 1);
+
+ return (DAYS_IN_YEAR * year_as_int) + number_of_leap_years;
+ }
+ static constexpr Date DAYS_TILL_ORIGINAL_BASE_YEAR;
};
+static constexpr TimerGameCalendar::Date DAYS_TILL_ORIGINAL_BASE_YEAR = TimerGameCalendar::DateAtStartOfYear(TimerGameCalendar::ORIGINAL_BASE_YEAR);
+
#endif /* TIMER_GAME_CALENDAR_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment