feat(infra/clock): injectable Clock with Real and Fake implementations

This commit is contained in:
2026-05-05 14:16:32 +08:00
parent 967f390b1e
commit c47d99d3d8
3 changed files with 110 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
// Package clock provides an injectable time source. Production code uses Real();
// tests use NewFake(t) to make time-based logic deterministic.
package clock
import "time"
// Clock is the abstraction over the system clock. Implementations must be
// safe for concurrent use.
type Clock interface {
Now() time.Time
}
type realClock struct{}
// Real returns a Clock backed by time.Now.
func Real() Clock { return realClock{} }
func (realClock) Now() time.Time { return time.Now() }