Clock Pattern makes time an explicit dependency. Application code depends on Clock, production wiring chooses a real
clock, and tests choose deterministic clocks.
Use this page as the documentation hub:
| Guide | Purpose |
|---|---|
| Usage Guide | How to inject clocks into application services and choose now() or today(). |
| Timezone Guide | UTC defaults, SystemClock timezone configuration, and date-boundary guidance. |
| Testing Guide | How to use FixedClock and MockClock for deterministic tests. |
Production imports:
from clock_pattern import Clock, SystemClock, UtcClockTesting imports:
from clock_pattern.clocks.testing import FixedClock, MockClockEvery clock exposes two methods:
| Method | Return type | Meaning |
|---|---|---|
now() |
datetime |
Current or prepared datetime for the clock implementation. |
today() |
date |
Current or prepared date for the clock implementation. |
SystemClock and UtcClock read real system time. FixedClock and MockClock are test utilities and should usually
stay in test code.
- Accept
Clockin domain services, application services, or use cases. - Wire
UtcClockorSystemClockat the application boundary. - Use
FixedClockwhen a test needs a stable instant. - Use
MockClockwhen a test also needs to assert that time was requested. - Keep timezone choices explicit, especially for date-only rules around midnight.