logicblocks.event.utils
logicblocks.event.utils
Section titled “logicblocks.event.utils”class Clock
Bases: ABC
Abstract source of the current time, replaceable in tests.
def now(tz: tzinfo | None = None) -> datetime
Get the current time.
Parameters:
tz(tzinfo | None) — The time zone to return the time in.
Returns:
datetime— the current time.
StaticClock
Section titled “StaticClock”class StaticClock(now: datetime)
Bases: Clock
A clock that always returns a fixed time until it is changed.
now ignores its tz argument and returns the time exactly as set.
Parameters:
now(datetime) — The time to return.
def set(now: datetime) -> None
Change the time the clock returns.
def now(tz: tzinfo | None = None) -> datetime
SystemClock
Section titled “SystemClock”class SystemClock
Bases: Clock
A clock that returns the system time via datetime.now.
def now(tz: tzinfo | None = None) -> datetime
TimezoneRequiredStaticClock
Section titled “TimezoneRequiredStaticClock”class TimezoneRequiredStaticClock(now: datetime, tz: tzinfo)
Bases: StaticClock
A static clock that requires callers to request a specific time zone.
Useful for asserting that code asks for times in the right time zone.
Times are converted to tz when set, and now raises a ValueError if
called with any other time zone.
Parameters:
now(datetime) — The time to return.tz(tzinfo) — The only time zonenowmay be called with.
def set(now: datetime) -> None
def now(tz: tzinfo | None = None) -> datetime