1#pragma once
2
3#include <chrono>
4#include <string>
5#include <common/DateLUT.h>
6
7
8namespace ext
9{
10 template <typename Clock, typename Duration = typename Clock::duration>
11 std::string to_string(const std::chrono::time_point<Clock, Duration> & tp)
12 {
13 return DateLUT::instance().timeToString(std::chrono::system_clock::to_time_t(tp));
14 }
15
16 template <typename Rep, typename Period = std::ratio<1>>
17 std::string to_string(const std::chrono::duration<Rep, Period> & dur)
18 {
19 auto seconds_as_int = std::chrono::duration_cast<std::chrono::seconds>(dur);
20 if (seconds_as_int == dur)
21 return std::to_string(seconds_as_int.count()) + "s";
22 auto seconds_as_double = std::chrono::duration_cast<std::chrono::duration<double>>(dur);
23 return std::to_string(seconds_as_double.count()) + "s";
24 }
25
26 template <typename Clock, typename Duration = typename Clock::duration>
27 std::ostream & operator<<(std::ostream & o, const std::chrono::time_point<Clock, Duration> & tp)
28 {
29 return o << to_string(tp);
30 }
31
32 template <typename Rep, typename Period = std::ratio<1>>
33 std::ostream & operator<<(std::ostream & o, const std::chrono::duration<Rep, Period> & dur)
34 {
35 return o << to_string(dur);
36 }
37}
38