2022-01-08 02:09:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <date/tz.h>
|
2022-01-08 06:25:15 +00:00
|
|
|
#include <fmt/format.h>
|
2022-01-08 02:09:44 +00:00
|
|
|
|
2023-01-17 00:48:30 +00:00
|
|
|
template <typename Duration, typename TimeZonePtr>
|
|
|
|
struct fmt::formatter<date::zoned_time<Duration, TimeZonePtr>> {
|
2022-01-08 06:25:15 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-08 02:09:44 +00:00
|
|
|
template <typename FormatContext>
|
2023-01-17 00:48:30 +00:00
|
|
|
auto format(const date::zoned_time<Duration, TimeZonePtr>& ztime, FormatContext& ctx) {
|
|
|
|
if (ctx.locale()) {
|
|
|
|
const auto loc = ctx.locale().template get<std::locale>();
|
|
|
|
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));
|
2022-01-08 02:09:44 +00:00
|
|
|
}
|
|
|
|
};
|