Allow month and year to wrap in timezone calculation
This commit is contained in:
parent
efcb292998
commit
82bfd0471f
1 changed files with 34 additions and 0 deletions
|
@ -32,6 +32,8 @@ void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
|
|||
tm.Minute = rtc_pcf.getMinute();
|
||||
tm.Second = rtc_pcf.getSecond();
|
||||
|
||||
int year = tm.Year;
|
||||
int month = tm.Month;
|
||||
int day = tm.Day;
|
||||
int hour = tm.Hour;
|
||||
int minute = tm.Minute;
|
||||
|
@ -54,6 +56,38 @@ void WatchyRTC::read(tmElements_t & tm, int offsetInSeconds) {
|
|||
hour = hour % 24;
|
||||
}
|
||||
|
||||
bool leapYear = year % 4 == 0;
|
||||
if (leapYear) {
|
||||
if (month == 2 && day > 29) {
|
||||
month++;
|
||||
day = day % 29;
|
||||
}
|
||||
} else {
|
||||
if (month == 2 && day > 28) {
|
||||
month++;
|
||||
day = day % 28;
|
||||
}
|
||||
}
|
||||
|
||||
if (month == 4 || month == 6 || month == 9 || month == 11) {
|
||||
if (day > 30) {
|
||||
month++;
|
||||
day = day % 30;
|
||||
}
|
||||
} else {
|
||||
if (day > 31) {
|
||||
month++;
|
||||
day = day % 31;
|
||||
}
|
||||
}
|
||||
|
||||
if (month > 12 || month < 0) {
|
||||
year++;
|
||||
month = month % 12;
|
||||
}
|
||||
|
||||
tm.Year = year;
|
||||
tm.Month = month;
|
||||
tm.Day = day;
|
||||
tm.Hour = hour;
|
||||
tm.Minute = minute;
|
||||
|
|
Loading…
Reference in a new issue