Some code refactoring in formatter

This commit is contained in:
gabime
2018-07-26 00:20:31 +03:00
parent a12a21a18e
commit de6ddf4e2a
2 changed files with 22 additions and 11 deletions

View File

@@ -4,6 +4,9 @@
#pragma once
#include "chrono"
#include "spdlog/fmt/fmt.h"
// Some fmt helpers to efficiently format and pad ints and strings
namespace spdlog {
namespace details {
@@ -110,6 +113,18 @@ inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
pad3(static_cast<int>(n % 1000), dest);
}
// return fraction of a second of the given time_point.
// e.g.
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
template<typename ToDuration>
ToDuration time_fraction(const log_clock::time_point &tp)
{
using namespace std::chrono;
auto duration = tp.time_since_epoch();
auto secs = duration_cast<seconds>(duration);
return duration_cast<ToDuration>(duration) - duration_cast<ToDuration>(secs);
}
} // namespace fmt_helper
} // namespace details
} // namespace spdlog