I need a Class able to store date and time information in UTC (no timezone/locale required) and I also need to perform basic arithmetic operations on those date/times (addition, subtraction) and comparison. Ideally I would like use the C++11 standard library, if that is possible.
std::chrono
seems a good candidate for my purposes. My DateTime
class could be as simple as an alias of chrono::time_point
with the desired precision. e.g.
using UTCTime = std::chrono::time_point<SomeClock>;
Defining a custom clock (SomeClock
) allows my class to be type safe, whilechrono::time_point
class provides the computational requirements.
The missing piece of the puzzle are the functions to convert to/from date and time information. chrono::system_clock
offers the methods to_time_t
and from_time_t
, which are limited by the precision of seconds, which is not good enough for me.
Does anybody have a solution for that?
Aucun commentaire:
Enregistrer un commentaire