Accrue.Clock (accrue v0.3.0)

Copy Markdown View Source

Canonical time source for Accrue (D3-86).

All code inside Accrue that needs "now" MUST call Accrue.Clock.utc_now/0 instead of DateTime.utc_now/0. In the test environment (:accrue, :env set to :test) this delegates to Accrue.Processor.Fake.now/0, which is backed by the Fake processor's in-memory test clock. In any other environment it delegates to the BEAM's DateTime.utc_now/0.

This indirection is what makes the Fake Processor the primary test surface (TEST-01): time-sensitive billing logic (trial ends, dunning, expiring-card notices) can be exercised deterministically by advancing the Fake clock rather than by sleeping or by stubbing DateTime.

Why application env, not compile env

The :env flag is read at runtime via Application.get_env/3 so host apps can flip it in tests without recompiling Accrue. Production never reaches the Fake branch because the default is :prod and host apps never set :accrue, :env to anything but :test.

Summary

Functions

utc_now()

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