clock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT 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 tells the services the time and writes times the one way the app does.

Services take a Clock so tests can set the time; System is the real one. Times the UI or the database reads are written with Format, in UTC as RFC 3339, and times in file names with Stamp, which sorts and has no characters a file name cannot hold.

Index

Constants

View Source
const StampLayout = "20060102T150405Z"

StampLayout is the layout of Stamp: a compact UTC time such as 20260102T150405Z.

Variables

This section is empty.

Functions

func Format

func Format(t time.Time) string

Format writes t in UTC as RFC 3339, the way every time the UI or the database reads is written.

func Sleep

func Sleep(ctx context.Context, d time.Duration) error

Sleep waits d on the real clock, or returns ctx's error once ctx ends first. A Clock can't make timers, so work that waits, as a merge's guard or a release's follow does, waits here and reads the time from the real clock too: in tests, from a synctest bubble's.

func Stamp

func Stamp(t time.Time) string

Stamp writes t in UTC in StampLayout, for file names.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock tells the time.

func Or

func Or(c Clock) Clock

Or returns c, or the real clock for nil.

type System

type System struct{}

System is the real clock.

func (System) Now

func (System) Now() time.Time

Now returns the current time.

Jump to

Keyboard shortcuts

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