Files
brianmcgee 27ea5601c5 {cmd, pkg}: remove direct calls to model.DefaultClock
Introduces a `config.Now` field which all components should defer to when getting the current time instead of hardcoded calls to `model.DefaultClock`.
2026-04-10 15:30:45 +01:00

18 lines
620 B
Go

package model
import "time"
// Clock is a type alias for a function that returns the current time as time.Time.
// It helps make time configurable within the system during testing.
//
// Any component which relies upon the current time should accept an instance to Clock as a parameter.
type Clock = func() time.Time
// Now returns the current UTC time truncated to the nearest millisecond.
// Any more precision than millisecond seems unnecessarily precise in a distributed system.
//
// It is the default clock to be used unless testing.
func Now() time.Time {
return time.Now().UTC().Truncate(time.Millisecond)
}