digclock

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 1 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() time.Time
	Since(time.Time) time.Duration
}

Clock defines how dig accesses time.

var System Clock = systemClock{}

System is the default implementation of Clock based on real time.

type Mock

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

Mock is a fake source of time. It implements standard time operations, but allows the user to control the passage of time.

Use the Mock.Add method to progress time.

Note that this implementation is not safe for concurrent use.

func NewMock

func NewMock() *Mock

NewMock creates a new mock clock with the current time set to the current time.

func (*Mock) Add

func (m *Mock) Add(d time.Duration)

Add progresses time by the given duration.

It panics if the duration is negative.

func (*Mock) Now

func (m *Mock) Now() time.Time

Now returns the current time.

func (*Mock) Since

func (m *Mock) Since(t time.Time) time.Duration

Since returns the time elapsed since the given time.

Jump to

Keyboard shortcuts

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