clock

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clock defines the clock interface and its fake for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time
}

Clock tells the current time. Code that needs the time takes a Clock, so a test can control it with Fake.

func Real

func Real() Clock

Real returns the Clock of the running program: Now is the system time in UTC.

type Fake

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

Fake is a Clock that only moves when a test says so. It is safe for concurrent use. Make it with NewFake.

func NewFake

func NewFake(t time.Time) *Fake

NewFake returns a Fake that starts at t, converted to UTC.

func (*Fake) Advance

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

Advance moves the Fake forward by d. A negative d moves it back.

func (*Fake) Now

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

Now returns the time of the Fake, in UTC.

func (*Fake) Set

func (f *Fake) Set(t time.Time)

Set moves the Fake to t, converted to UTC. t may be earlier than the current time.

Jump to

Keyboard shortcuts

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