diff --git a/include/timestamp.h b/include/timestamp.h index 027796c..6911767 100644 --- a/include/timestamp.h +++ b/include/timestamp.h @@ -72,6 +72,22 @@ public: * Default constructs the timestamp. */ Timestamp() : tv() {} + + #if TINS_IS_CXX11 + /** + * Constructs a Timestamp from a std::chrono::duration. + */ + template + Timestamp(const std::chrono::duration& ts) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + using std::chrono::seconds; + + tv.tv_sec = duration_cast(ts).count(); + tv.tv_usec = duration_cast( + ts - seconds(tv.tv_sec)).count(); + } + #endif /** * Constructs a timestamp from a timeval object.