From 5eb6e19c5130b28963e9555f6c73835ac30d817d Mon Sep 17 00:00:00 2001 From: deanlee Date: Fri, 26 Nov 2021 23:12:37 +0800 Subject: [PATCH] lambda get_time_str --- selfdrive/boardd/boardd.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 66ffb70baa..b0385bf850 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -62,12 +62,6 @@ std::atomic pigeon_active(false); ExitHandler do_exit; -std::string get_time_str(const struct tm &time) { - char s[30] = {'\0'}; - std::strftime(s, std::size(s), "%Y-%m-%d %H:%M:%S", &time); - return s; -} - bool check_all_connected(const std::vector &pandas) { for (const auto& panda : pandas) { if (!panda->connected) { @@ -83,6 +77,12 @@ enum class SyncTimeDir { TO_PANDA, FROM_PANDA }; void sync_time(Panda *panda, SyncTimeDir dir) { if (!panda->has_rtc) return; + auto get_time_str = [](const struct tm &time) { + char s[30] = {'\0'}; + std::strftime(s, std::size(s), "%Y-%m-%d %H:%M:%S", &time); + return std::string(s); + }; + setenv("TZ", "UTC", 1); struct tm sys_time = util::get_time(); struct tm rtc_time = panda->get_rtc(); @@ -94,7 +94,7 @@ void sync_time(Panda *panda, SyncTimeDir dir) { if (std::abs(seconds) > 1.1) { panda->set_rtc(sys_time); LOGW("Updating panda RTC. dt = %.2f System: %s RTC: %s", - seconds, get_time_str(sys_time).c_str(), get_time_str(rtc_time).c_str()); + seconds, get_time_str(sys_time).c_str(), get_time_str(rtc_time).c_str()); } } } else if (dir == SyncTimeDir::FROM_PANDA) {