[#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&period;

== Synopsis

Declared in `&lt;absl&sol;time&sol;clock&lowbar;interface&period;h&gt;`

[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&period; You can use this to your advantage by injecting Clocks into interfaces rather than having implementations call absl&colon;&colon;Now() directly&period;

Implementations of this interface must be thread&hyphen;safe&period;

The Clock&colon;&colon;GetRealClock() function returns a reference to the global realtime clock&period;

Example&colon;

bool IsWeekend(Clock&amp; clock) &lcub; absl&colon;&colon;Time now &equals; clock&period;TimeNow()&semi; &sol;&sol; &period;&period;&period; code to check if &apos;now&apos; is a weekend&period; &rcub;

&sol;&sol; Production code&period; IsWeekend(Clock&colon;&colon;GetRealClock())&semi;

&sol;&sol; Test code&colon; MyTestClock test&lowbar;clock(SATURDAY)&semi; IsWeekend(test&lowbar;clock)&semi;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/Clock/2destructor.adoc[`&#126;Clock`] [.small]#[destructor]# [.small]#[virtual]#
| Destroys the clock&period;
| xref:absl/Clock/AwaitWithDeadline.adoc[`AwaitWithDeadline`]  [.small]#[virtual]#
| Returns when cond is true or the deadline has passed&period; Returns true iff cond holds when returning&period;
| xref:absl/Clock/Sleep.adoc[`Sleep`]  [.small]#[virtual]#
| Sleeps for the specified duration&period;
| xref:absl/Clock/SleepUntil.adoc[`SleepUntil`]  [.small]#[virtual]#
| Sleeps until the specified time&period;
| xref:absl/Clock/TimeNow.adoc[`TimeNow`]  [.small]#[virtual]#
| Returns the current time&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/Clock/GetRealClock.adoc[`GetRealClock`] 
| Returns a reference to the global realtime clock&period; The returned clock is thread&hyphen;safe&period;
|===


== Derived Classes

[cols="1,4"]
|===
| Name| Description
| xref:absl/SimulatedClock.adoc[`SimulatedClock`] 
| A simulated clock is a concrete Clock implementation that does not &quot;tick&quot; on its own&period; Time is advanced by explicit calls to the AdvanceTime() or SetTime() functions&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
