Skip to content

Commit 6b020a3

Browse files
committed
mbed_localtime: Add support of year day.
This field is needed by the LPC43XX targets.
1 parent 01f1e08 commit 6b020a3

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void test_local_time() {
186186
expected->tm_mon != actual_value.tm_mon ||
187187
expected->tm_year != actual_value.tm_year ||
188188
expected->tm_wday != actual_value.tm_wday ||
189+
expected->tm_yday != actual_value.tm_yday ||
189190
result == false
190191
) {
191192
printf("error: i = %lu\r\n", i);
@@ -213,6 +214,9 @@ void test_local_time() {
213214
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
214215
expected->tm_wday, actual_value.tm_wday, "invalid weekday"
215216
);
217+
TEST_ASSERT_EQUAL_UINT32_MESSAGE(
218+
expected->tm_yday, actual_value.tm_yday, "invalid year day"
219+
);
216220
}
217221
}
218222

platform/mbed_mktime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ bool _rtc_localtime(time_t timestamp, struct tm* time_info) {
143143
}
144144
}
145145

146+
time_info->tm_yday = timestamp;
147+
146148
// convert days into seconds and find the current month
147149
timestamp *= SECONDS_BY_DAY;
148150
time_info->tm_mon = 11;

platform/mbed_mktime.h

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

0 commit comments

Comments
 (0)