Skip to content

Commit

Permalink
Added correct handling of leap-years, #23
Browse files Browse the repository at this point in the history
  • Loading branch information
SV-Zanshin authored May 3, 2023
1 parent 5fe99af commit 23f3f67
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/DS3231M.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static uint16_t date2days(uint16_t y, uint8_t m, uint8_t d) {
for (uint8_t i = 1; i < m; ++i) {
days += pgm_read_byte(daysInMonth + i - 1); // Add number of days for each month
} // for-next each month
if (m > 2 && y % 4 == 0) {
if (m > 2 && (((y % 4 == 0) && (y % 100 != 0)) ||
(y % 400 == 0))) {
++days; // Deal with leap years
} // if-then leap year
return days + 365 * y + (y + 3) / 4 - 1; // Return computed value
Expand Down

0 comments on commit 23f3f67

Please sign in to comment.