#pragma once #include #if HAVE_CHRONO_TIMEZONES #include #else #include #include #include #endif // Date namespace date { #if HAVE_CHRONO_TIMEZONES using namespace std::chrono; using namespace std; #else using system_clock = std::chrono::system_clock; using seconds = std::chrono::seconds; template inline auto format(const char* spec, const T& arg) { return date::format(std::regex_replace(spec, std::regex("\\{:L|\\}"), ""), arg); } template inline auto format(const std::locale& loc, const char* spec, const T& arg) { return date::format(loc, std::regex_replace(spec, std::regex("\\{:L|\\}"), ""), arg); } #endif } // namespace date // Format namespace waybar::util::date::format { #if HAVE_CHRONO_TIMEZONES using namespace std; #else using namespace fmt; #endif } // namespace waybar::util::date::format #if not HAVE_CHRONO_TIMEZONES 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)); } }; #endif using namespace date;