Add time_t conversions for gc_clock

`gc_clock` reports system time, and these conversion functions allow for
manipulating time points produced by the clock without making assumptions about
its epoch.
This commit is contained in:
Jesse Haber-Kucharsky
2017-06-21 10:46:16 -04:00
parent 4ef25e8e38
commit 73020685ee

View File

@@ -42,6 +42,14 @@ public:
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<gc_clock, duration>;
static constexpr std::time_t to_time_t(time_point t) {
return std::chrono::duration_cast<std::chrono::seconds>(t.time_since_epoch()).count();
}
static constexpr time_point from_time_t(std::time_t t) {
return time_point(std::chrono::duration_cast<duration>(std::chrono::seconds(t)));
}
static time_point now() {
return time_point(std::chrono::duration_cast<duration>(base::now().time_since_epoch())) + get_clocks_offset();
}