using static constexpr char array as default format
This commit is contained in:
parent
c6f8112a06
commit
aab4a1bfa2
@ -451,24 +451,16 @@ FMT_END_DETAIL_NAMESPACE
|
||||
template <typename Char, typename Duration>
|
||||
struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
||||
Char> : formatter<std::tm, Char> {
|
||||
FMT_CONSTEXPR FMT_INLINE void generate_default_spec(char) {
|
||||
this->specs = {"%Y-%m-%d %H:%M:%S", 17};
|
||||
}
|
||||
FMT_CONSTEXPR FMT_INLINE void generate_default_spec(wchar_t) {
|
||||
this->specs = {L"%Y-%m-%d %H:%M:%S", 17};
|
||||
}
|
||||
|
||||
template <typename ParseContext>
|
||||
FMT_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) {
|
||||
generate_default_spec(typename ParseContext::char_type{});
|
||||
} else {
|
||||
if (end == it)
|
||||
this->specs = {default_spec, 17};
|
||||
else
|
||||
this->specs = {it, detail::to_unsigned(end - it)};
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
@ -478,6 +470,10 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
||||
std::tm time = localtime(val);
|
||||
return formatter<std::tm, Char>::format(time, ctx);
|
||||
}
|
||||
|
||||
static constexpr Char default_spec[] = {'%', 'Y', '-', '%', 'm', '-',
|
||||
'%', 'd', ' ', '%', 'H', ':',
|
||||
'%', 'M', ':', '%', 'S'};
|
||||
};
|
||||
|
||||
template <typename Char> struct formatter<std::tm, Char> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user