[#absl-Clock] = xref:absl.adoc[absl]::Clock :relfileprefix: ../ :mrdocs: An abstract interface representing a Clock, which is an object that can tell you the current time, sleep, and wait for a condition variable. == Synopsis Declared in `<absl/time/clock_interface.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class Clock; ---- == Description This interface allows decoupling code that uses time from the code that creates a point in time. You can use this to your advantage by injecting Clocks into interfaces rather than having implementations call absl::Now() directly. Implementations of this interface must be thread‐safe. The Clock::GetRealClock() function returns a reference to the global realtime clock. Example: bool IsWeekend(Clock& clock) { absl::Time now = clock.TimeNow(); // ... code to check if 'now' is a weekend. } // Production code. IsWeekend(Clock::GetRealClock()); // Test code: MyTestClock test_clock(SATURDAY); IsWeekend(test_clock); == Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Clock/2destructor.adoc[`~Clock`] [.small]#[destructor]# [.small]#[virtual]# | Destroys the clock. | xref:absl/Clock/AwaitWithDeadline.adoc[`AwaitWithDeadline`] [.small]#[virtual]# | Returns when cond is true or the deadline has passed. Returns true iff cond holds when returning. | xref:absl/Clock/Sleep.adoc[`Sleep`] [.small]#[virtual]# | Sleeps for the specified duration. | xref:absl/Clock/SleepUntil.adoc[`SleepUntil`] [.small]#[virtual]# | Sleeps until the specified time. | xref:absl/Clock/TimeNow.adoc[`TimeNow`] [.small]#[virtual]# | Returns the current time. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Clock/GetRealClock.adoc[`GetRealClock`] | Returns a reference to the global realtime clock. The returned clock is thread‐safe. |=== == Derived Classes [cols="1,4"] |=== | Name| Description | xref:absl/SimulatedClock.adoc[`SimulatedClock`] | A simulated clock is a concrete Clock implementation that does not "tick" on its own. Time is advanced by explicit calls to the AdvanceTime() or SetTime() functions. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#