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