Skip to content

Commit da95415

Browse files
committed
Fix for STM32 HAL_RTC_GetDate year. Fixes #6618.
1 parent 31aac92 commit da95415

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

wolfcrypt/src/wc_port.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,8 +3253,10 @@ time_t stm32_hal_time(time_t *t1)
32533253
HAL_RTC_GetTime(&hrtc, &time, FORMAT_BIN);
32543254
HAL_RTC_GetDate(&hrtc, &date, FORMAT_BIN);
32553255

3256-
tm_time.tm_year = date.Year;
3257-
tm_time.tm_mon = date.Month - 1; /* gm starts at 0 */
3256+
/* RTC year is 0-99 and "struct tm" is 1900+, so assume after year 2000 */
3257+
tm_time.tm_year = date.Year + 100;
3258+
/* RTC month is 1-12 and "struct tm" is 0-12, so subtract 1 */
3259+
tm_time.tm_mon = date.Month - 1;
32583260
tm_time.tm_mday = date.Date;
32593261
tm_time.tm_hour = time.Hours;
32603262
tm_time.tm_min = time.Minutes;

0 commit comments

Comments
 (0)