refactor(clock): extract waybar_time to util/waybar_time.hpp

This commit is contained in:
Aleksei Bavshin
2022-01-07 18:09:44 -08:00
parent d9b5c2595a
commit c0d84853ea
3 changed files with 37 additions and 24 deletions

View File

@ -6,12 +6,13 @@
#include <sstream>
#include <type_traits>
#include "util/ustring_clen.hpp"
#include "util/waybar_time.hpp"
#ifdef HAVE_LANGINFO_1STDAY
#include <langinfo.h>
#include <locale.h>
#endif
using waybar::modules::waybar_time;
using waybar::waybar_time;
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
: ALabel(config, "clock", id, "{:%H:%M}", 60, false, false, true),
@ -227,14 +228,3 @@ auto waybar::modules::Clock::first_day_of_week() -> date::weekday {
#endif
return date::Sunday;
}
template <>
struct fmt::formatter<waybar_time> : fmt::formatter<std::tm> {
template <typename FormatContext>
auto format(const 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));
}
};