dm: rtc: Try to handle the localtime() race
authorSimon Glass <sjg@chromium.org>
Mon, 1 Aug 2022 13:58:48 +0000 (07:58 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 2 Sep 2022 20:21:44 +0000 (16:21 -0400)
commit21ddac140e3040b2693c1a5558a84c19a879c04f
tree91e5c815982e9f1823f86f61bc49e28d948d1b4c
parentfc7ceae0d5b7a017c3fed88a8bfe2eb3d24058a9
dm: rtc: Try to handle the localtime() race

At present the sandbox timer uses localtime() which can jump around twice
a year when daylight-saving time changes.

It would be tricky to make use of gmtime() since we still need to present
the time in local time, as seems to be required by U-Boot's RTC interface.

The problem can only happen once, so use a loop to detect it and try
again. This should be sufficient to detect either a change in the 'second'
value, or a daylight-saving change. We can assume that the latter also
incorporates a 'second' change, so there is no need to loop more than
twice.

Signed-off-by: Simon Glass <sjg@chromium.org>
test/dm/rtc.c