timeutil

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package timeutil exports functions and types related to time and date.

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
}

A Clock is an object that can tell you the current time.

This interface allows decoupling code that uses time from the code that creates a point in time. You can use this to your advantage by injecting Clocks into interfaces rather than having implementations call time.Now() directly.

Use RealClock() in production. Use SimulatedClock() in test.

func NewRealClock

func NewRealClock() Clock

type SimulatedClock

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

A SimulatedClock is a concrete Clock implementation that doesn't "tick" on its own. Time is advanced by explicit call to the AdvanceTime() or SetTime() functions. This object is concurrency safe.

func NewSimulatedClock

func NewSimulatedClock(t time.Time) *SimulatedClock

func (*SimulatedClock) AdvanceTime

func (c *SimulatedClock) AdvanceTime(d time.Duration)

func (*SimulatedClock) Now

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

func (*SimulatedClock) SetTime

func (c *SimulatedClock) SetTime(t time.Time)

Jump to

Keyboard shortcuts

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