clock

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 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 provides the Emulator clock (NFR-REL-002): real by default, or under --deterministic a fake clock that moves once per API request. Both can be advanced with `gcpemu time advance`, and set back to their base with `gcpemu time reset`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestStep added in v0.10.0

func RequestStep(c Clock)

RequestStep moves c one request step if it is a Stepper; the real clock is not, so the call is a no-op there.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock reports the emulator's notion of time.

type Fake

type Fake struct {
	Step time.Duration
	// contains filtered or unexported fields
}

Fake is a deterministic clock that starts at a fixed instant and moves forward by Step on each RequestStep; Now never moves it, so every read within one request returns the same instant (ADR 0020).

func NewFake

func NewFake() *Fake

NewFake returns a fake clock starting at 2026-01-01T00:00:00Z.

func (*Fake) Now

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

func (*Fake) RequestStep added in v0.10.0

func (f *Fake) RequestStep()

RequestStep moves the clock forward by Step, as an API request arriving at a Deterministic Instance does.

type Offset

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

Offset is a clock that can be advanced, over a real or fake base.

func NewOffset

func NewOffset(base Clock) *Offset

NewOffset wraps base with an advanceable offset.

func (*Offset) Advance

func (o *Offset) Advance(d time.Duration)

Advance moves the clock forward by d.

func (*Offset) Now

func (o *Offset) Now() time.Time

func (*Offset) Read added in v0.16.0

func (o *Offset) Read() (now time.Time, offset time.Duration)

Read reports the time and how far the clock has been advanced past its base, both from one instant.

func (*Offset) RequestStep added in v0.10.0

func (o *Offset) RequestStep()

RequestStep moves a fake base clock one request step.

func (*Offset) Reset added in v0.16.0

func (o *Offset) Reset() time.Time

Reset sets the offset back to zero, so the clock reads its base again, and returns the time it then reads.

type Real

type Real struct{}

Real is the wall clock.

func (Real) Now

func (Real) Now() time.Time

type Stepper added in v0.10.0

type Stepper interface {
	RequestStep()
}

Stepper is a clock that moves once per API request (ADR 0020).

type Stopwatch added in v0.6.0

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

Stopwatch times short intervals such as a loopback round trip. Go's monotonic clock on Windows advances only every ~0.5ms, so a fast hop timed with time.Since reads as zero there; Stopwatch reads a high-resolution counter instead.

func StartStopwatch added in v0.6.0

func StartStopwatch() Stopwatch

StartStopwatch starts a Stopwatch now.

func (Stopwatch) Elapsed added in v0.6.0

func (s Stopwatch) Elapsed() time.Duration

Elapsed is the time since the Stopwatch started.

Jump to

Keyboard shortcuts

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