clock

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package clock provides the injectable clock (go-conventions.md "Time").

Everything that checks validity, schedules renewals or writes audit entries takes a Clock instead of calling time.Now, so tests control time exactly – certificate tests must never depend on the wall clock. Times are UTC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sleep added in v0.3.0

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

Sleep is the production wait; scheduling code injects Fake.Sleep in tests.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock returns the current time in UTC.

type Fake

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

Fake is a manually controlled clock for tests. It is safe for concurrent use; time only moves when Set or Advance is called.

func NewFake

func NewFake(t time.Time) *Fake

NewFake returns a fake clock standing at t (converted to UTC).

func (*Fake) Advance

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

Advance moves the clock forward by d and returns the new time.

func (*Fake) Now

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

Now returns the fake time.

func (*Fake) Set

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

Set moves the clock to t (converted to UTC); it may go backwards, which lets tests simulate a wrong system clock.

func (*Fake) Sleep added in v0.3.0

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

Sleep waits until Set or Advance reaches the deadline, or ctx ends.

func (*Fake) Waiting added in v0.3.0

func (f *Fake) Waiting() int

Waiting is the number of registered waits, for deterministic test barriers.

type System

type System struct{}

System is the real clock.

func (System) Now

func (System) Now() time.Time

Now returns the current wall-clock time in UTC. It is the only place outside tests that may read the wall clock.

Jump to

Keyboard shortcuts

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