clock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 2 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

This section is empty.

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.

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