apply utc offset and handle underflow

This commit is contained in:
Jacob Dahl
2025-04-16 01:39:17 -08:00
parent 46d82bbba9
commit f12abf058b
+10 -1
View File
@@ -1296,6 +1296,16 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si
px4_clock_gettime(CLOCK_REALTIME, &ts);
timestamp_utc = ts.tv_sec + (ts.tv_nsec / 1e9);
// Apply UTC offset parameter and handle potential underflow
int32_t utc_offset_seconds = _param_sdlog_utc_offset.get() * 60;
if (utc_offset_seconds < 0 && timestamp_utc < (uint32_t)abs(utc_offset_seconds)) {
timestamp_utc = 0;
} else {
timestamp_utc += utc_offset_seconds;
}
const char *replay_suffix = "";
if (_replay_file_name) {
@@ -1315,7 +1325,6 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si
// Check if time is non-zero for valid UTC timestamp
if (timestamp_utc > 0) {
timestamp_utc += _param_sdlog_utc_offset.get() * 60;
tm tt = {};
gmtime_r(&timestamp_utc, &tt);