Injectable clock used for lease expiry and event timestamps.
Rheo reads time through this behaviour so tests can advance time without
Process.sleep/1 via Rheo.Clock.Frozen.
Callback
See utc_now/0.
Example implementation
defmodule MyApp.Clock do
@behaviour Rheo.Clock
@impl true
def utc_now, do: DateTime.utc_now() |> DateTime.truncate(:millisecond)
endConfigure with:
config :rheo, clock: MyApp.Clock
Summary
Callbacks
@callback utc_now() :: DateTime.t()
Returns the current UTC time.
Examples
defmodule Demo.Clock do
@behaviour Rheo.Clock
@impl true
def utc_now, do: ~U[2026-01-15 12:00:00.000Z]
endReturns
A DateTime.t() in UTC, typically truncated to milliseconds.
Functions
@spec impl() :: module()
Returns the configured clock module.
Defaults to Rheo.Clock.System when :clock is unset.
Examples
iex> is_atom(Rheo.Clock.impl())
trueReturns
A module implementing Rheo.Clock.
@spec utc_now() :: DateTime.t()
Current UTC time according to the configured clock.
Examples
iex> match?(%DateTime{}, Rheo.Clock.utc_now())
true