#pragma once #include #if HAVE_CHRONO_TIMEZONES #include #include /* Compatibility layer for on top of C++20 */ namespace date { using namespace std::chrono; namespace literals { using std::chrono::last; } inline auto format(const std::string& spec, const auto& ztime) { return spec.empty() ? "" : std::vformat("{:L" + spec + "}", std::make_format_args(ztime)); } inline auto format(const std::locale& loc, const std::string& spec, const auto& ztime) { return spec.empty() ? "" : std::vformat(loc, "{:L" + spec + "}", std::make_format_args(ztime)); } } // namespace date #else #include #endif template struct fmt::formatter> { std::string_view specs; template constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(); if (it != ctx.end() && *it == ':') { ++it; } auto end = it; while (end != ctx.end() && *end != '}') { ++end; } if (end != it) { specs = {it, std::string_view::size_type(end - it)}; } return end; } template auto format(const date::zoned_time& ztime, FormatContext& ctx) { if (ctx.locale()) { const auto loc = ctx.locale().template get(); return fmt::format_to(ctx.out(), "{}", date::format(loc, fmt::to_string(specs), ztime)); } return fmt::format_to(ctx.out(), "{}", date::format(fmt::to_string(specs), ztime)); } };