From e0151944ffaaf206240c9072ca8b9b11a526c673 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 18 Aug 2025 13:22:27 +0800 Subject: [PATCH] fix(log): fixed wrong year timestamp with LOG_TIMESTAMP_SOURCE_SYSTEM_FULL struct tm contains the number of years since 1900, but the printing code assumed it contained actual current year. It would also print it as YYYY, while the documentation and code implies it should be YY. Closes https://github.com/espressif/esp-idf/issues/17451 --- components/log/src/log_timestamp_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/log/src/log_timestamp_common.c b/components/log/src/log_timestamp_common.c index 16b4a69c4b..932877aa45 100644 --- a/components/log/src/log_timestamp_common.c +++ b/components/log/src/log_timestamp_common.c @@ -106,8 +106,9 @@ char* esp_log_timestamp_str(bool constrained_env, uint64_t timestamp_ms, char* b uint64_t msec = timestamp_ms % 1000; localtime_r(&sec, &timeinfo); #if CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM_FULL + uint32_t year = (timeinfo.tm_year + 1900) % 100; // it takes 22 bytes to output it in the format: "YY-MM-DD HH:MM:SS.sss" - buffer += esp_log_util_cvt_dec(timeinfo.tm_year, 2, buffer); + buffer += esp_log_util_cvt_dec(year, 2, buffer); *buffer++ = '-'; buffer += esp_log_util_cvt_dec(timeinfo.tm_mon + 1, 2, buffer); *buffer++ = '-';