diff --git a/ds3231.hpp b/ds3231.hpp index 62bf497..2f48644 100644 --- a/ds3231.hpp +++ b/ds3231.hpp @@ -24,7 +24,7 @@ struct Time { struct DateTime : Date, Time { }; -template +template class DS3231 { public: static constexpr auto I2C_ADDRESS = 0x68; @@ -125,6 +125,13 @@ class DS3231 { static_assert(type::always_false_v, "Invalid register address"); } } + + static uint8_t calcDayOfWeek(uint16_t year, uint8_t month, uint16_t day) + { + day += month < 3 ? year-- : year - 2; + const auto dayOfWeek = (23 * month / 9 + day + 4 + year / 4 - year / 100 + year / 400); + return dayOfWeek % 7; + } }; } // namespace rtc