Commit 98ade8b6 authored by Kenton Varda's avatar Kenton Varda Committed by Kenton Varda

Add Clock interface to time.h, for reading the current wall time / date.

parent 956ca5fd
...@@ -30,6 +30,15 @@ kj::Exception Timer::makeTimeoutException() { ...@@ -30,6 +30,15 @@ kj::Exception Timer::makeTimeoutException() {
return KJ_EXCEPTION(OVERLOADED, "operation timed out"); return KJ_EXCEPTION(OVERLOADED, "operation timed out");
} }
Clock& nullClock() {
class NullClock final: public Clock {
public:
Date now() override { return UNIX_EPOCH; }
};
static NullClock NULL_CLOCK;
return NULL_CLOCK;
}
struct TimerImpl::Impl { struct TimerImpl::Impl {
struct TimerBefore { struct TimerBefore {
bool operator()(TimerPromiseAdapter* lhs, TimerPromiseAdapter* rhs); bool operator()(TimerPromiseAdapter* lhs, TimerPromiseAdapter* rhs);
......
...@@ -61,6 +61,16 @@ using Date = Absolute<Duration, _::DateLabel>; ...@@ -61,6 +61,16 @@ using Date = Absolute<Duration, _::DateLabel>;
constexpr Date UNIX_EPOCH = origin<Date>(); constexpr Date UNIX_EPOCH = origin<Date>();
// The `Date` representing Jan 1, 1970 00:00:00 UTC. // The `Date` representing Jan 1, 1970 00:00:00 UTC.
class Clock {
// Interface to read the current date and time.
public:
virtual Date now() = 0;
};
Clock& nullClock();
// A clock which always returns UNIX_EPOCH as the current time. Useful when you don't care about
// time.
class Timer { class Timer {
// Interface to time and timer functionality. // Interface to time and timer functionality.
// //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment