diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-04-19 13:13:21 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-05-08 11:47:45 +0200 |
commit | faa5c62967174f1dd66e8a4ba61ab29c867cf450 (patch) | |
tree | 9772ce56976ae4806db2c93e383611fdcde134c4 /src/util/time.h | |
parent | 59ac8bacd573891d84e8ab96ff43ea12bd266f26 (diff) |
Add time helpers for std::chrono::steady_clock
Diffstat (limited to 'src/util/time.h')
-rw-r--r-- | src/util/time.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util/time.h b/src/util/time.h index 9d92b23725..041b8aa6a1 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -14,6 +14,10 @@ using namespace std::chrono_literals; +using SteadySeconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::seconds>; +using SteadyMilliseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds>; +using SteadyMicroseconds = std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds>; + void UninterruptibleSleep(const std::chrono::microseconds& n); /** @@ -67,6 +71,15 @@ std::chrono::seconds GetMockTime(); /** Return system time (or mocked time, if set) */ template <typename T> T GetTime(); +/** + * Return the current time point cast to the given precicion. Only use this + * when an exact precicion is needed, otherwise use T::clock::now() directly. + */ +template <typename T> +T Now() +{ + return std::chrono::time_point_cast<typename T::duration>(T::clock::now()); +} /** * ISO 8601 formatting is preferred. Use the FormatISO8601{DateTime,Date} |