Hi,
I'm currently working on a ble mesh project with 2 nodes using nrf Connect SDK v1.4.2 with toolchain 1.4.2:
- Device A with Time Client Model - nrf52840
- Device B with Time Server - nrf5340
Dev.A sends the following time status to Dev.B in order to update its time:
struct bt_mesh_time_status status = {
.tai = {
.sec = 667930834 + k_uptime_get() / 1000,
.subsec = 1,
},
.uncertainty = 0,
.tai_utc_delta = 37,
.time_zone_offset = 0,
.is_authority = true,
};
Those specific TAI seconds indicate a time in the afternoon of 2021/03/01, but bt_mesh_time_srv_localtime's output called on Dev.B returns
a struct tm with the following values:

that is 2021/02/29.
So I looked at the code using the debugger:

The tai_to_ts function of time_util.c correctly calculates 2021 as a non-leap year, but no check is made on the increment at line 107.
I ran another test by adding 1 day (86400 seconds) to the above time status and the localtime returns 2021/03/02, as if March 1 did not exist.
Is this a bug?
Adding the following check at the same line could solve the problem:
if (day_cnt + 1 > months[timeptr->tm_mon]) {
timeptr->tm_mday = 1;
timeptr->tm_mon++;
} else
timeptr->tm_mday = day_cnt + 1;
Regards,
A. Pochiero