STMicroelectronics / STM32CubeWL

STM32Cube MCU Full FW Package for the STM32WL series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on boards provided by ST (Nucleo boards)
Other
107 stars 54 forks source link

SysTimeLocalTime returns incorrect month #47

Closed Shensenz closed 2 years ago

Shensenz commented 2 years ago

The SysTimeLocalTime() function in the stm32_systime module fills in wrong month in the struct. Precisely, it calls CalendarGetMonth, which, if it's August or a subsequent, gets the month off by one. For example, it gets July correctly as 7, then August as 7 again, September as 8 and so on.

The CalendarGetMonth itself is easy to fix, but after its call the day of the year is calculated, and the math there depends on the month value. The day calculation works fine as it is, but if a correct month is fed, it gets the day incorrect.

There is some fancy math in the functions so a proper fix would not be straightforward. Suggest some workaround e.g. change 7 to 8 in the CalendarGetMonth, then conditionally pass decremented value to the day calculation statement.

Shensenz commented 2 years ago

Oh, sorry, my bad. It's just month counting from 0. Not an issue.