construct much more tmp variables

std::chrono::seconds -= std::chrono::milliseconds cannot be done bc
it represents the duration as integer value and milliseconds are less
than seconds. it causes compilation error when we pass a duration to
toml::local_time. to avoid this, we need to type-cast the values to
smaller duration, like sec -> msec
This commit is contained in:
ToruNiina
2018-12-09 18:00:46 +09:00
parent 2696e4e6ba
commit dc8ccdc458

View File

@@ -145,21 +145,21 @@ struct local_time
{} {}
template<typename Rep, typename Period> template<typename Rep, typename Period>
explicit local_time(std::chrono::duration<Rep, Period> t) explicit local_time(const std::chrono::duration<Rep, Period>& t)
{ {
const auto h = std::chrono::duration_cast<std::chrono::hours>(t); const auto h = std::chrono::duration_cast<std::chrono::hours>(t);
this->hour = h.count(); this->hour = h.count();
t -= h; const auto t2 = t - h;
const auto m = std::chrono::duration_cast<std::chrono::minutes>(t); const auto m = std::chrono::duration_cast<std::chrono::minutes>(t2);
this->minute = m.count(); this->minute = m.count();
t -= m; const auto t3 = t2 - m;
const auto s = std::chrono::duration_cast<std::chrono::seconds>(t); const auto s = std::chrono::duration_cast<std::chrono::seconds>(t3);
this->second = s.count(); this->second = s.count();
t -= s; const auto t4 = t3 - s;
const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(t); const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(t4);
this->millisecond = ms.count(); this->millisecond = ms.count();
t -= ms; const auto t5 = t4 - ms;
const auto us = std::chrono::duration_cast<std::chrono::microseconds>(t); const auto us = std::chrono::duration_cast<std::chrono::microseconds>(t5);
this->microsecond = us.count(); this->microsecond = us.count();
} }