times

package module
v0.0.0-...-03e9105 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 2 Imported by: 0

README

times

A Go package that provides utilities for reproducible testing of time sensitive logic.

Documentation:


Made in Berlin, DE

Documentation

Overview

Package times provides a clock interface with implementations for production and testing code.

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

	// After returns a channel that can be used to receive the current time once, after the specified
	// duration has passed.
	After(time.Duration) <-chan time.Time
}

Clock defines an interface with primitives for time related functionality.

func Sys

func Sys() Clock

Sys returns the Clock implementation based on the standard library time functions. Meant to be used with production code.

type TestClock

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

TestClock is a test implementation of the Clock interface. On top of the Clock methods, it adds the possibility to manually step time or to virtually jump to a specified time.

func Test

func Test() TestClock

Test creates a Clock implementation with manual time stepping function. Meant to be used with testing code.

func TestFrom

func TestFrom(t time.Time) TestClock

TestFrom creates a Clock implementation with manual time stepping function, starting from the specified time. Meant to be used with testing code.

func (TestClock) After

func (c TestClock) After(d time.Duration) <-chan time.Time

After returns a channel that communicates the current time if the specified duration has passed.

func (TestClock) Jump

func (c TestClock) Jump(t time.Time)

Jump sets the clock to time specified by t. Values of t in the past, relative to TestClock's current time, are ignored.

func (TestClock) Now

func (c TestClock) Now() time.Time

Now returns the current test time.

func (TestClock) Pass

func (c TestClock) Pass(d time.Duration)

Pass turns the clock forward by d duration. Negative d is considered as 0.

func (TestClock) Waiting

func (c TestClock) Waiting() int

Waiting tells how many channels are waiting set by After().

Jump to

Keyboard shortcuts

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