From 650573bda80c99fb83b9d077f8e4402c7adf9bf8 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 12 Feb 2025 11:13:51 +0530 Subject: [PATCH 1/2] esp32: Fix incorrect RTC log format in SystemTimeSupport --- src/platform/ESP32/SystemTimeSupport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/ESP32/SystemTimeSupport.cpp b/src/platform/ESP32/SystemTimeSupport.cpp index 613e79b6067858..a91516d67a30f1 100644 --- a/src/platform/ESP32/SystemTimeSupport.cpp +++ b/src/platform/ESP32/SystemTimeSupport.cpp @@ -95,8 +95,8 @@ CHIP_ERROR ClockImpl::SetClock_RealTime(Microseconds64 aNewCurTime) struct tm calendar; localtime_r(&timep, &calendar); ChipLogProgress(DeviceLayer, "Real time clock set to %lld (%04d/%02d/%02d %02d:%02d:%02d UTC)", - static_cast(tv.tv_sec), calendar.tm_year, calendar.tm_mon, calendar.tm_mday, calendar.tm_hour, - calendar.tm_min, calendar.tm_sec); + static_cast(tv.tv_sec), calendar.tm_year + 1900, calendar.tm_mon + 1, calendar.tm_mday, + calendar.tm_hour, calendar.tm_min, calendar.tm_sec); } #endif // CHIP_PROGRESS_LOGGING return CHIP_NO_ERROR; From ba897174999b3bd2afd71e40247dafa529a68ad7 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 12 Feb 2025 17:07:37 +0530 Subject: [PATCH 2/2] esp32: used strftime for formatting --- src/platform/ESP32/SystemTimeSupport.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/ESP32/SystemTimeSupport.cpp b/src/platform/ESP32/SystemTimeSupport.cpp index a91516d67a30f1..266bef5e67389a 100644 --- a/src/platform/ESP32/SystemTimeSupport.cpp +++ b/src/platform/ESP32/SystemTimeSupport.cpp @@ -94,9 +94,9 @@ CHIP_ERROR ClockImpl::SetClock_RealTime(Microseconds64 aNewCurTime) const time_t timep = tv.tv_sec; struct tm calendar; localtime_r(&timep, &calendar); - ChipLogProgress(DeviceLayer, "Real time clock set to %lld (%04d/%02d/%02d %02d:%02d:%02d UTC)", - static_cast(tv.tv_sec), calendar.tm_year + 1900, calendar.tm_mon + 1, calendar.tm_mday, - calendar.tm_hour, calendar.tm_min, calendar.tm_sec); + char time_str[64]; + strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S UTC", &calendar); + ChipLogProgress(DeviceLayer, "Real time clock set to %lld (%s)", static_cast(tv.tv_sec), time_str); } #endif // CHIP_PROGRESS_LOGGING return CHIP_NO_ERROR;