1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Timestamps can now be constructed from std::chrono::duration.

This commit is contained in:
Matias Fontanini
2014-08-07 20:12:19 -03:00
parent 282cd0913c
commit 1b47623484

View File

@@ -72,6 +72,22 @@ public:
* Default constructs the timestamp.
*/
Timestamp() : tv() {}
#if TINS_IS_CXX11
/**
* Constructs a Timestamp from a std::chrono::duration.
*/
template<typename Rep, typename Period>
Timestamp(const std::chrono::duration<Rep, Period>& ts) {
using std::chrono::duration_cast;
using std::chrono::microseconds;
using std::chrono::seconds;
tv.tv_sec = duration_cast<seconds>(ts).count();
tv.tv_usec = duration_cast<microseconds>(
ts - seconds(tv.tv_sec)).count();
}
#endif
/**
* Constructs a timestamp from a timeval object.