mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix(util): make waybar_time formatter compatible with fmt 8.1.0
Stop using private implementation details of the `formatter<std::tm>`. We never needed anything from the class besides the format specifier, which is easily obtainable with public API.
This commit is contained in:
parent
1489a539f8
commit
7f6bef2049
@ -1,12 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
#if FMT_VERSION < 60000
|
|
||||||
#include <fmt/time.h>
|
|
||||||
#else
|
|
||||||
#include <fmt/chrono.h>
|
|
||||||
#endif
|
|
||||||
#include <date/tz.h>
|
#include <date/tz.h>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
@ -18,12 +13,27 @@ struct waybar_time {
|
|||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct fmt::formatter<waybar::waybar_time> : fmt::formatter<std::tm> {
|
struct fmt::formatter<waybar::waybar_time> {
|
||||||
|
std::string_view specs;
|
||||||
|
|
||||||
|
template <typename ParseContext>
|
||||||
|
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 <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const waybar::waybar_time& t, FormatContext& ctx) {
|
auto format(const waybar::waybar_time& t, FormatContext& ctx) {
|
||||||
#if FMT_VERSION >= 80000
|
return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(specs), t.ztime));
|
||||||
auto& tm_format = specs;
|
|
||||||
#endif
|
|
||||||
return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(tm_format), t.ztime));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
#include "modules/clock.hpp"
|
#include "modules/clock.hpp"
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#if FMT_VERSION < 60000
|
||||||
|
#include <fmt/time.h>
|
||||||
|
#else
|
||||||
|
#include <fmt/chrono.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "util/ustring_clen.hpp"
|
#include "util/ustring_clen.hpp"
|
||||||
#include "util/waybar_time.hpp"
|
#include "util/waybar_time.hpp"
|
||||||
#ifdef HAVE_LANGINFO_1STDAY
|
#ifdef HAVE_LANGINFO_1STDAY
|
||||||
|
Loading…
Reference in New Issue
Block a user