diff --git a/platform/mbed_mktime.c b/platform/mbed_mktime.c index 5b43ddd6bf..aac26bfb74 100644 --- a/platform/mbed_mktime.c +++ b/platform/mbed_mktime.c @@ -123,6 +123,11 @@ bool _rtc_localtime(time_t timestamp, struct tm* time_info) { time_info->tm_hour = timestamp % 24; timestamp = timestamp / 24; // timestamp in days; + // compute the weekday + // The 1st of January 1970 was a Thursday which is equal to 4 in the weekday + // representation ranging from [0:6] + time_info->tm_wday = (timestamp + 4) % 7; + // years start at 70 time_info->tm_year = 70; while (true) { diff --git a/platform/mbed_mktime.h b/platform/mbed_mktime.h index 33a2723494..1d12c7db27 100644 --- a/platform/mbed_mktime.h +++ b/platform/mbed_mktime.h @@ -80,6 +80,7 @@ time_t _rtc_mktime(const struct tm* calendar_time); * - tm_mday * - tm_mon * - tm_year + * - tm_wday * The object remains untouched if the time in input is invalid. * @return true if the conversion was successful, false otherwise. *