keeltime

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 1 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 keeltime provides a replaceable clock for deterministic tests.

Code reads the current time through Now. Tests can switch it to a fixed time with Static or to a strictly increasing time with Incremental. The package variables are not synchronized; switch providers before concurrent use.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Now returns the current time. It defaults to [time.Now] and is replaced
	// by [Static] and [Incremental].
	Now = time.Now
	// NowStaticNSec is the Unix time in nanoseconds returned by the static
	// provider (2021-01-01 11:00:00 UTC).
	NowStaticNSec = int64(1609498800e9)
	// NowIncrementalNSec is the Unix time in nanoseconds the incremental
	// provider returns next.
	NowIncrementalNSec = NowStaticNSec
)

Functions

func Incremental

func Incremental()

Incremental sets Now to return NowIncrementalNSec and advance it by one nanosecond on each call. It is not safe for concurrent use.

func ResetIncremental

func ResetIncremental()

ResetIncremental resets NowIncrementalNSec to NowStaticNSec.

func Static

func Static()

Static sets Now to always return NowStaticNSec.

Types

This section is empty.

Jump to

Keyboard shortcuts

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