2
0
mirror of https://github.com/gabime/spdlog.git synced 2026-01-19 04:52:09 +00:00

Fix %z when pattern_type_type is utc - should be +00:00

This commit is contained in:
gabime
2026-01-03 11:30:50 +02:00
parent 32dd298dc2
commit 09a674b7fc

View File

@@ -514,8 +514,9 @@ public:
template <typename ScopedPadder>
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<details::z_formatter<Padder>>(padding));
formatters_.push_back(
details::make_unique<details::z_formatter<Padder>>(padding, pattern_time_type_));
need_localtime_ = true;
break;
case ('P'): // pid