DripDrop.Clock behaviour (DripDrop v0.1.0)

Copy Markdown View Source

Centralized UTC clock helpers.

Production code uses these instead of DateTime.utc_now/1 directly so the second-precision policy and any future test-time clock freezing live in one place. The clock is swappable via config :dripdrop, :clock, MyClock where MyClock implements the now/0 callback — useful for freezing time in flaky timezone or DST tests.

All helpers truncate to the second by design. Sub-second precision is not used in DripDrop schemas and would only invite drift between code paths.

Summary

Functions

Returns the current UTC time truncated to the second.

Returns now() + seconds. Pass a negative value for a past timestamp.

Returns datetime + seconds truncated to the second.

Callbacks

now()

@callback now() :: DateTime.t()

Functions

now()

@spec now() :: DateTime.t()

Returns the current UTC time truncated to the second.

seconds_from_now(seconds)

@spec seconds_from_now(integer()) :: DateTime.t()

Returns now() + seconds. Pass a negative value for a past timestamp.

Replaces the recurring DateTime.utc_now(:second) |> DateTime.add(N, :second) pattern.

shift(datetime, seconds)

@spec shift(DateTime.t(), integer()) :: DateTime.t()

Returns datetime + seconds truncated to the second.