diff --git a/include/util/waybar_time.hpp b/include/util/waybar_time.hpp index 3eaf1146..c74e58c3 100644 --- a/include/util/waybar_time.hpp +++ b/include/util/waybar_time.hpp @@ -1,12 +1,7 @@ #pragma once -#include -#if FMT_VERSION < 60000 -#include -#else -#include -#endif #include +#include namespace waybar { @@ -18,12 +13,27 @@ struct waybar_time { } // namespace waybar template <> -struct fmt::formatter : fmt::formatter { +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 waybar::waybar_time& t, FormatContext& ctx) { -#if FMT_VERSION >= 80000 - auto& tm_format = specs; -#endif - return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(tm_format), t.ztime)); + return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(specs), t.ztime)); } }; diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 739b79d1..b0a6776a 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,10 +1,16 @@ #include "modules/clock.hpp" -#include #include +#if FMT_VERSION < 60000 +#include +#else +#include +#endif +#include #include #include + #include "util/ustring_clen.hpp" #include "util/waybar_time.hpp" #ifdef HAVE_LANGINFO_1STDAY