clock

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: BSD-2-Clause Imports: 8 Imported by: 4

README

clock

A go library that provides for unit testable time constructs.

Documentation

Index

Constants

View Source
const (
	Day         = 24 * time.Hour
	SimpleDate1 = "2006-01-02"
	SimpleDate2 = "2026/01/02"
	UsDate1     = "01-02-2006"
)

Variables

This section is empty.

Functions

func ParseDurationWithDays added in v1.1.4

func ParseDurationWithDays(value string) (time.Duration, error)

func ParseTimeOrRelativeDuration added in v1.1.4

func ParseTimeOrRelativeDuration(value string, now time.Time) (time.Time, error)

Types

type Clock

type Clock interface {
	Now() time.Time
	NewTimer(d time.Duration) Timer
	AfterFunc(d time.Duration, f func()) Timer
	WithTimeout(parent context.Context, d time.Duration) (context.Context, context.CancelFunc)
}

type FakeClock

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

func NewFakeClock

func NewFakeClock(now time.Time) *FakeClock

func (*FakeClock) Advance

func (f *FakeClock) Advance(d time.Duration)

func (*FakeClock) AfterFunc

func (f *FakeClock) AfterFunc(d time.Duration, fn func()) Timer

func (*FakeClock) NewTimer

func (f *FakeClock) NewTimer(d time.Duration) Timer

func (*FakeClock) Now

func (f *FakeClock) Now() time.Time

func (*FakeClock) WithTimeout

func (f *FakeClock) WithTimeout(parent context.Context, d time.Duration) (context.Context, context.CancelFunc)

type FakeDeadlineContext

type FakeDeadlineContext struct {
	context.Context
	// contains filtered or unexported fields
}

func (*FakeDeadlineContext) Deadline

func (ctx *FakeDeadlineContext) Deadline() (deadline time.Time, ok bool)

func (*FakeDeadlineContext) Done

func (ctx *FakeDeadlineContext) Done() <-chan struct{}

func (*FakeDeadlineContext) Err

func (ctx *FakeDeadlineContext) Err() error

type FakeTimer

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

func (*FakeTimer) C

func (f *FakeTimer) C() <-chan time.Time

func (*FakeTimer) Less

func (f *FakeTimer) Less(rhs *FakeTimer) bool

func (*FakeTimer) Reset

func (f *FakeTimer) Reset(d time.Duration) bool

func (*FakeTimer) Stop

func (f *FakeTimer) Stop() bool

type RealClock

type RealClock struct{}

func NewRealClock

func NewRealClock() *RealClock

func (RealClock) AfterFunc

func (r RealClock) AfterFunc(d time.Duration, f func()) Timer

func (RealClock) NewTimer

func (r RealClock) NewTimer(d time.Duration) Timer

func (RealClock) Now

func (r RealClock) Now() time.Time

func (RealClock) WithTimeout

func (r RealClock) WithTimeout(parent context.Context, d time.Duration) (context.Context, context.CancelFunc)

type RealTimer

type RealTimer struct {
	*time.Timer
}

func (RealTimer) C

func (r RealTimer) C() <-chan time.Time

type Timer

type Timer interface {
	Stop() bool
	C() <-chan time.Time
	Reset(d time.Duration) bool
}

Jump to

Keyboard shortcuts

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