From 09a674b7fc167ce182c4d971a58dc6f9f3426a63 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 3 Jan 2026 11:30:50 +0200 Subject: [PATCH] Fix %z when pattern_type_type is utc - should be +00:00 --- include/spdlog/pattern_formatter-inl.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/spdlog/pattern_formatter-inl.h b/include/spdlog/pattern_formatter-inl.h index 1c59663b..eba67333 100644 --- a/include/spdlog/pattern_formatter-inl.h +++ b/include/spdlog/pattern_formatter-inl.h @@ -514,8 +514,9 @@ public: template class z_formatter final : public flag_formatter { public: - explicit z_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} + explicit z_formatter(padding_info padinfo, pattern_time_type time_type) + : flag_formatter(padinfo), + time_type_(time_type) {} z_formatter() = default; z_formatter(const z_formatter &) = delete; @@ -525,6 +526,11 @@ public: const size_t field_size = 6; ScopedPadder p(field_size, padinfo_, dest); + if (time_type_ == pattern_time_type::utc) { + dest.append("+00:00", "+00:00" + 6); + return; + } + #ifdef SPDLOG_NO_TZ_OFFSET const char *str = "+??:??"; dest.append(str, str + 6); @@ -545,6 +551,7 @@ public: } private: + pattern_time_type time_type_; log_clock::time_point last_update_{std::chrono::seconds(0)}; int offset_minutes_{0}; @@ -1161,7 +1168,8 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i need_localtime_ = true; break; case ('z'): // timezone - formatters_.push_back(details::make_unique>(padding)); + formatters_.push_back( + details::make_unique>(padding, pattern_time_type_)); need_localtime_ = true; break; case ('P'): // pid