jsclock

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package jsclock is the process clock of JavaScript's Date.now() and performance.now(), with a replaceable source. Upstream tests replace both with vi.spyOn; Go keeps the replacement here so telemetry adapters read the same clock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateNow

func DateNow() float64

DateNow is Date.now(): whole milliseconds since the Unix epoch.

func PerformanceNow

func PerformanceNow() float64

PerformanceNow is performance.now(): fractional milliseconds on a monotonic clock since process start.

Types

type Mock

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

Mock is a replacement for one clock, set like vi.spyOn(...).mockReturnValue.

func MockDateNow

func MockDateNow(initial float64) (*Mock, func())

MockDateNow replaces Date.now() with a constant that returns initial until Set. The returned restore reinstalls the real clock, as vi.restoreAllMocks does.

func MockPerformanceNow

func MockPerformanceNow(initial float64) (*Mock, func())

MockPerformanceNow replaces performance.now() like MockDateNow.

func (*Mock) Set

func (mock *Mock) Set(value float64)

Set is mockReturnValue.

Jump to

Keyboard shortcuts

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