27 #include <nlohmann/json.hpp>
31 std::chrono::nanoseconds parse_duration_to_nanoseconds(
const std::string& s);
55 template <
typename Duration>
57 return std::chrono::duration_cast<Duration>(parse_duration_to_nanoseconds(s));
60 template <
typename Duration>
61 std::string to_string(
const Duration& d) {
62 return to_string(std::chrono::duration_cast<std::chrono::nanoseconds>(d));
66 std::string to_string(
const std::chrono::nanoseconds& d);
72 template <
typename Rep,
typename Period>
73 struct adl_serializer<std::chrono::duration<Rep, Period>> {
74 using Duration = std::chrono::duration<Rep, Period>;
76 static void to_json(json& j,
const Duration& d) {
77 j = ::fable::to_string(d);
80 static void from_json(
const json& j, Duration& d) {
81 std::string s = j.get<std::string>();
82 d = ::fable::parse_duration<Duration>(s);
Duration parse_duration(const std::string &s)
Definition: chrono.hpp:56