From 9fadf71a10c88917219cbfb8c182f4e3c96145f9 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 9 Dec 2018 16:27:47 +0900 Subject: [PATCH] add constructor from duration to local_time --- toml/datetime.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/toml/datetime.hpp b/toml/datetime.hpp index bf455ba..82d283b 100644 --- a/toml/datetime.hpp +++ b/toml/datetime.hpp @@ -144,6 +144,25 @@ struct local_time millisecond(0), microsecond(0) {} + template + explicit local_time(std::chrono::duration t) + { + const auto h = std::chrono::duration_cast(t); + this->hour = h.count(); + t -= h; + const auto m = std::chrono::duration_cast(t); + this->minute = m.count(); + t -= m; + const auto s = std::chrono::duration_cast(t); + this->second = s.count(); + t -= s; + const auto ms = std::chrono::duration_cast(t); + this->millisecond = ms.count(); + t -= ms; + const auto us = std::chrono::duration_cast(t); + this->microsecond = us.count(); + } + operator std::chrono::microseconds() const { return std::chrono::microseconds(this->microsecond) +