Skip to content

Commit 01f1e08

Browse files
committed
mbed_localtime: Add support of wday.
This field is necessary, it is used by several vendor RTC: Atmel, ST, NUVOTON, NXP.
1 parent 946ed35 commit 01f1e08

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

platform/mbed_mktime.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ bool _rtc_localtime(time_t timestamp, struct tm* time_info) {
123123
time_info->tm_hour = timestamp % 24;
124124
timestamp = timestamp / 24; // timestamp in days;
125125

126+
// compute the weekday
127+
// The 1st of January 1970 was a Thursday which is equal to 4 in the weekday
128+
// representation ranging from [0:6]
129+
time_info->tm_wday = (timestamp + 4) % 7;
130+
126131
// years start at 70
127132
time_info->tm_year = 70;
128133
while (true) {

platform/mbed_mktime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ time_t _rtc_mktime(const struct tm* calendar_time);
8080
* - tm_mday
8181
* - tm_mon
8282
* - tm_year
83+
* - tm_wday
8384
* The object remains untouched if the time in input is invalid.
8485
* @return true if the conversion was successful, false otherwise.
8586
*

0 commit comments

Comments
 (0)