clock

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time
}

Clock is a small interface abstracting time operations the package needs. Use this to inject testable/fake clocks in unit tests rather than relying on time.Now directly.

func Default added in v1.0.0

func Default() Clock

Default returns the process default clock.

func OrDefault added in v1.0.0

func OrDefault(c Clock) Clock

OrDefault returns c unless it is nil, in which case the default clock is returned.

type OsClock

type OsClock struct{}

OsClock is a production Clock that delegates to time.Now.

func (OsClock) Now

func (OsClock) Now() time.Time

Now returns the current wall-clock time.

type TestClock

type TestClock struct {
	// contains filtered or unexported fields
}

TestClock is a simple, mutex-protected, manually-advancable clock useful for tests. It allows deterministic control of Now() by setting an initial time and advancing it as needed.

func NewTestClock

func NewTestClock(initial time.Time) *TestClock

NewTestClock constructs a TestClock seeded to the provided time.

func (*TestClock) Advance

func (c *TestClock) Advance(d time.Duration)

Advance moves the TestClock forward by d.

func (*TestClock) Now

func (c *TestClock) Now() time.Time

Now returns the current time of the TestClock.

func (*TestClock) Set

func (c *TestClock) Set(t time.Time)

Set sets the TestClock to a specific time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL