LeviLamina
Loading...
Searching...
No Matches
TmWithMs.h
1#pragma once
2
3#include <ctime>
4
5#include "fmt/base.h"
6#include "ll/api/base/StdInt.h"
7
8#include "fmt/chrono.h"
9
10namespace ll::data {
11struct TmWithMs : public std::tm {
12 ushort ms;
13};
14} // namespace ll::data
15
16template <typename Char>
17struct fmt::formatter<ll::data::TmWithMs, Char> : formatter<std::tm, Char> {
18private:
19 detail::arg_ref<Char> precisionRef;
20 fmt::format_specs specs;
21
22public:
23 constexpr formatter() {
24 parse_context<Char> ctx{detail::string_literal<Char, '%', 'T'>{}};
25 this->do_parse(ctx, false);
26 }
27
28 template <typename FormatContext>
29 auto format(ll::data::TmWithMs const& val, FormatContext& ctx) const -> decltype(ctx.out()) {
30 formatter<std::tm, Char>::format(val, ctx);
31 auto out = ctx.out();
32 if (specs.precision > 0) {
33 fmt::format_to(out, "{0:0>{1}}", val.ms, specs.precision);
34 }
35 return out;
36 }
37 constexpr auto parse(basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) {
38 auto it = ctx.begin(), end = ctx.end();
39 if (it == end || *it == '}') return it;
40 if (*it == '.') {
41 it = detail::parse_precision(it, end, specs, precisionRef, ctx);
42 }
43 ctx.advance_to(it);
44 return formatter<std::tm, Char>::parse(ctx);
45 }
46};
Definition ctx.h:5
Definition TmWithMs.h:11