From 9315b8f1b66ee655927a864af2bf0eae6b22dc77 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Sat, 17 Aug 2019 11:30:07 -0400 Subject: [PATCH] Fix RTC local time formatting (timezone offset) when no valid date/time Timezone shouldn't be applied to the "default" invalid date as it can cause underflow for negative timezone offsets. --- src/main/blackbox/blackbox.c | 6 +++--- src/main/common/time.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index ad787be2e4..a5a722726b 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1187,15 +1187,15 @@ static bool sendFieldDefinition(char mainFrameChar, char deltaFrameChar, const v // Buf must be at least FORMATTED_DATE_TIME_BUFSIZE STATIC_UNIT_TESTED char *blackboxGetStartDateTime(char *buf) { - #ifdef USE_RTC_TIME +#ifdef USE_RTC_TIME dateTime_t dt; // rtcGetDateTime will fill dt with 0000-01-01T00:00:00 // when time is not known. rtcGetDateTime(&dt); dateTimeFormatLocal(buf, &dt); - #else +#else buf = "0000-01-01T00:00:00.000"; - #endif +#endif return buf; } diff --git a/src/main/common/time.c b/src/main/common/time.c index c15f104626..707cad7c38 100644 --- a/src/main/common/time.c +++ b/src/main/common/time.c @@ -200,7 +200,8 @@ bool dateTimeFormatUTC(char *buf, dateTime_t *dt) bool dateTimeFormatLocal(char *buf, dateTime_t *dt) { - return dateTimeFormat(buf, dt, timeConfig()->tz_offsetMinutes, false); + const int16_t timezoneOffset = rtcIsDateTimeValid(dt) ? timeConfig()->tz_offsetMinutes : 0; + return dateTimeFormat(buf, dt, timezoneOffset, false); } bool dateTimeFormatLocalShort(char *buf, dateTime_t *dt)