mercredi 29 juillet 2015

How do I convert YYYY/MM/DD HH:MM:SS to std::chrono::system_clock::time_point?

I'm obtaining YYYY/MM/DD HH:MM:SS components from an offboard real time clock chip. I want to convert this to a std::chrono::system_clock::timepoint so that I may obtain the seconds since the Epoch and update the operating system's time.

I would like to use Howard Hinnant's proposed date library to perform this conversion.

I would intuitively do something like this:

date::year_month_day ymd = ...;
date::time_of_day tod = ...;
auto sysTime = date + tod;

but I don't see an appropriate operator+ overload for this. Am I missing something?

Another use case for this type of conversion is to convert a calendar date and time into a std::chrono::timepoint that I can pass to boost::asio::steady_timer.

Aucun commentaire:

Enregistrer un commentaire