Skip to content

Commit d68220b

Browse files
Merge pull request #150 from martinayotte/master
Stm32F4. Fix bug related to missing 7 days in getTime()
2 parents 2f97268 + c9d796c commit d68220b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

STM32F4/libraries/RTClock/src/RTClock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,17 @@ time_t RTClock::getTime() {
219219
int secs = 10 * ((tr_reg & 0x00000070) >> 4) + (tr_reg & 0x0000000F);
220220
// seconds from 1970 till 1 jan 00:00:00 of the given year
221221
time_t t = (years + 30) * SECS_PER_DAY * 365;
222-
for (int i = 0; i < years; i++) {
222+
for (int i = 0; i < (years + 30); i++) {
223223
if (LEAP_YEAR(i)) {
224224
t += SECS_PER_DAY; // add extra days for leap years
225225
}
226226
}
227227
// add days for this year, months start from 1
228228
for (int i = 1; i < months; i++) {
229229
if ( (i == 2) && LEAP_YEAR(years)) {
230-
t += SECS_PER_DAY * 29;
230+
t += SECS_PER_DAY * 29;
231231
} else {
232-
t += SECS_PER_DAY * monthDays[i - 1]; //monthDays array starts from 0
232+
t += SECS_PER_DAY * monthDays[i - 1]; //monthDays array starts from 0
233233
}
234234
}
235235
t += (days - 1) * SECS_PER_DAY + hours * SECS_PER_HOUR + mins * SECS_PER_MIN + secs;

0 commit comments

Comments
 (0)