Current section
Files
Jump to
Current section
Files
src/bigben@clock.erl
-module(bigben@clock).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/bigben/clock.gleam").
-export([new/0, now/1, from_fake/1]).
-export_type([clock/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" A clock.\n").
-opaque clock() :: {clock, fun(() -> birl:time())}.
-file("src/bigben/clock.gleam", 12).
?DOC(" Returns a new `Clock`.\n").
-spec new() -> clock().
new() ->
{clock, fun birl:utc_now/0}.
-file("src/bigben/clock.gleam", 17).
?DOC(" Returns the current time on the given `Clock`, in UTC.\n").
-spec now(clock()) -> birl:time().
now(Clock) ->
(erlang:element(2, Clock))().
-file("src/bigben/clock.gleam", 22).
?DOC(" Returns a new `Clock` constructed from the given `FakeClock`.\n").
-spec from_fake(bigben@fake_clock:fake_clock()) -> clock().
from_fake(Clock) ->
{clock, fun() -> bigben@fake_clock:now(Clock) end}.