clock

package module
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 1 Imported by: 0

README

Tests on Linux, MacOS and Windows Go Report Card GoDoc

This package provides a ticking clock that allows you to set the start time. It also provides a system clock, both implementing this interface:

// Clock provides the sub set of methods in time.Time that this package provides.
type Clock interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	Until(t time.Time) time.Duration

	// Offset returns the offset of this clock relative to the system clock.
	Offset() time.Duration
}

Note that this only support a subset of all the methods in time.Time (see above) and is by design very simple. If you're looking for a more advanced time mocking library, have a look at https://github.com/benbjohnson/clock.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimeCupFinalNorway1976 = time.Date(1976, time.October, 24, 12, 15, 2, 127686412, time.UTC)

TimeCupFinalNorway1976 is the start time in UTC for the final match of the 1976 Norwegian Football Cup. This is typically used in tests where you need a historic time with a special meaning.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	Until(t time.Time) time.Duration

	// Offset returns the offset of this clock relative to the system clock.
	Offset() time.Duration
}

Clock provides the sub set of methods in time.Time that this package provides.

func Fixed added in v0.4.0

func Fixed(t time.Time) Clock

Fixed returns a Clock that always returns the given time.

func Start

func Start(t time.Time) Clock

Start creates a new Clock starting at t.

func System added in v0.3.0

func System() Clock

System is a Clock that uses the system clock, meaning it just delegates to time.Now() etc.

Source Files

Jump to

Keyboard shortcuts

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