mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' into master
This commit is contained in:
@ -1,21 +1,14 @@
|
||||
#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 "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
namespace waybar {
|
||||
|
||||
struct waybar_time {
|
||||
std::locale locale;
|
||||
date::zoned_seconds ztime;
|
||||
};
|
||||
struct waybar_time;
|
||||
|
||||
namespace modules {
|
||||
|
||||
const std::string kCalendarPlaceholder = "calendar";
|
||||
|
||||
@ -43,4 +36,5 @@ class Clock : public ALabel {
|
||||
bool is_timezone_fixed();
|
||||
};
|
||||
|
||||
} // namespace waybar::modules
|
||||
} // namespace modules
|
||||
} // namespace waybar
|
||||
|
39
include/util/waybar_time.hpp
Normal file
39
include/util/waybar_time.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <date/tz.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace waybar {
|
||||
|
||||
struct waybar_time {
|
||||
std::locale locale;
|
||||
date::zoned_seconds ztime;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
||||
template <>
|
||||
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>
|
||||
auto format(const waybar::waybar_time& t, FormatContext& ctx) {
|
||||
return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(specs), t.ztime));
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user