clock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClock

func WithClock(ctx context.Context, clock Clock) context.Context

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 ClockFromContext

func ClockFromContext(ctx context.Context) Clock

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