timeutil

package module
Version: v0.0.0-...-577e5ac Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2017 License: Apache-2.0 Imports: 6 Imported by: 101

README

GoDoc

This package contains code that supplements the time package from the Go standard library. In particular:

  • A Clock interface, with a fake implementation that can be used in tests.
  • Implementations of oglematchers.Matcher for time values.

See the reference for more info.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeEq

func TimeEq(t time.Time) oglematchers.Matcher

Return a matcher for times that are exactly equal to the given input time according to the == operator, which compares on location, instant, and monotonic clock reading.

If you want to ignore location, canonicalize using Time.UTC. If you want to ignore ignore monotonic clock reading, strip it using Time.AddDate(0, 0, 0) (cf. https://goo.gl/rYU5UI).

func TimeNear

func TimeNear(t time.Time, d time.Duration) oglematchers.Matcher

Return a matcher for times whose absolute distance from t is less than d.

Types

type Clock

type Clock interface {
	Now() time.Time
}

func RealClock

func RealClock() Clock

Return a clock that follows the real time, according to the system.

type SimulatedClock

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

A clock that allows for manipulation of the time, which does not change unless AdvanceTime is called. The zero value is a clock initialized to the zero time.

func (*SimulatedClock) AdvanceTime

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

Advance the current time according to the clock by the supplied duration.

func (*SimulatedClock) Now

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

func (*SimulatedClock) SetTime

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

Set the current time according to the clock.

Jump to

Keyboard shortcuts

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