From: Kefu Chai Date: Tue, 27 Aug 2019 16:50:06 +0000 (+0800) Subject: crimson/net/ProtocolV2: include fmt/chrono.h if fmt version >= 6.0 X-Git-Tag: v15.1.0~1746^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9d0ff5b3b9d032c0625487ecbd266caf78cac831;p=ceph-ci.git crimson/net/ProtocolV2: include fmt/chrono.h if fmt version >= 6.0 * check libfmt version instead of the exisistence of chrono.h, as libfmt merged fmt/time.h into fmt/chrono.h since v 6.0, while in libfmt v5.3, fmt/chrono.h did not provide all the necessary bits for fmt::to_format(..., const tm&). see also https://github.com/fmtlib/fmt/commit/a939c75956d27996680ce498529da0d1668c4eac and https://github.com/fmtlib/fmt/blob/master/ChangeLog.rst * use fmt API instead of libc API for getting `localtime()`, it's more C++ friendly than plain `localtime_r()` Signed-off-by: Kefu Chai --- diff --git a/src/crimson/net/ProtocolV2.cc b/src/crimson/net/ProtocolV2.cc index a475c535d4e..6d4003b8978 100644 --- a/src/crimson/net/ProtocolV2.cc +++ b/src/crimson/net/ProtocolV2.cc @@ -5,7 +5,7 @@ #include #include -#if __has_include() +#if FMT_VERSION >= 60000 #include #else #include @@ -95,9 +95,8 @@ inline uint64_t generate_client_cookie() { } // namespace anonymous -namespace fmt { template <> -struct formatter { +struct fmt::formatter { // ignore the format string template constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } @@ -105,17 +104,14 @@ struct formatter { template auto format(const seastar::lowres_system_clock::time_point& t, FormatContext& ctx) { - struct tm bdt; - time_t tt = std::chrono::duration_cast( + std::time_t tt = std::chrono::duration_cast( t.time_since_epoch()).count(); - localtime_r(&tt, &bdt); auto milliseconds = (t.time_since_epoch() % std::chrono::seconds(1)).count(); - return format_to(ctx.out(), "{:%Y-%m-%d %H:%M:%S} {:03d}", - bdt, milliseconds); + return fmt::format_to(ctx.out(), "{:%Y-%m-%d %H:%M:%S} {:03d}", + fmt::localtime(tt), milliseconds); } }; -} namespace std { inline ostream& operator<<(