mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-28 10:41:12 +00:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user