I'm working on a specific implementation in C++. Suppose that I have a date::year_month_day variable from Howard Hinnant's date library called X and I want to convert it to a std::chrono::time_point that represents the same time as X but with an added offset of A hours, B minutes and C seconds.
How can I achieve this?
using namespace std::chrono;
auto tp = date::sys_days{X} + hours{A} + minutes{B} + seconds{C};
The type of tp is std::chrono::time_point<system_clock, seconds>, and represents a time point in UTC.
The only thing Howard Hinnant's date library adds in this example is the conversion from date::year_month_day to sys_days, which itself is just a typedef for time_point<system_clock, days>. After that conversion, you're working entirely within the C++11/14 <chrono> library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With