Skip to content

Commit b232d34

Browse files
authored
Merge pull request #10 from fpistm/DOW_Issue
Fix week day issue
2 parents 1c0c41a + 1b10c6b commit b232d34

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/STM32RTC.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,12 @@ uint32_t STM32RTC::getEpoch(void)
851851
syncTime();
852852

853853
tm.tm_isdst = -1;
854+
/*
855+
* mktime ignores the values supplied by the caller in the
856+
* tm_wday and tm_yday fields
857+
*/
854858
tm.tm_yday = 0;
855-
tm.tm_wday = _wday - 1;
859+
tm.tm_wday = 0;
856860
tm.tm_year = _year + EPOCH_TIME_YEAR_OFF;
857861
tm.tm_mon = _month - 1;
858862
tm.tm_mday = _day;
@@ -911,7 +915,11 @@ void STM32RTC::setEpoch(uint32_t ts)
911915
_year = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
912916
_month = tmp->tm_mon + 1;
913917
_day = tmp->tm_mday;
914-
_wday = tmp->tm_wday + 1;
918+
if(tmp->tm_wday == 0) {
919+
_wday = RTC_WEEKDAY_SUNDAY;
920+
} else {
921+
_wday = tmp->tm_wday;
922+
}
915923
_hours = tmp->tm_hour;
916924
_minutes = tmp->tm_min;
917925
_seconds = tmp->tm_sec;

0 commit comments

Comments
 (0)