time2

package
v0.0.0-...-436d200 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

time2 is a collection of functions meant to supplement the capabilities provided by the standard "time" package.

Index

Constants

This section is empty.

Variables

View Source
var DefaultClock = &realClock{}

Functions

func NowFloat

func NowFloat() float64

Return the time as a float64, ala Python's time.time().

func TimeToFloat

func TimeToFloat(t time.Time) float64

Convert Time to epoch seconds with subsecond precision.

Types

type Clock

type Clock interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	After(d time.Duration) <-chan time.Time
	Sleep(d time.Duration)
}

These methods are all equivalent to those provided by the time package

type MockClock

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

A fake clock useful for testing timing.

func NewMockClock

func NewMockClock(now time.Time) *MockClock

func (*MockClock) Advance

func (c *MockClock) Advance(delta time.Duration)

Advances the mock clock by the specified duration.

func (*MockClock) AdvanceTo

func (c *MockClock) AdvanceTo(t time.Time)

Advance to a specific time.

func (*MockClock) AdvanceToNextWakeup

func (c *MockClock) AdvanceToNextWakeup()

func (*MockClock) After

func (c *MockClock) After(d time.Duration) <-chan time.Time

func (*MockClock) NextWakeupTime

func (c *MockClock) NextWakeupTime() time.Time

func (*MockClock) Now

func (c *MockClock) Now() time.Time

Returns the fake current time.

func (*MockClock) NowFloat

func (c *MockClock) NowFloat() float64

Returns the fake current time in epoch seconds.

func (*MockClock) Set

func (c *MockClock) Set(t time.Time)

Set the mock clock to a specific time. NOTE: scheduled wakeup calls are not modified when resetting the clock to an earlier time; for example, suppose the current time is X, and there is a pending wakeup call at time X+1. If we reset the clock to X-2, the wakeup time will still be at X+1.

func (*MockClock) SetLogf

func (c *MockClock) SetLogf(f func(format string, args ...interface{}))

func (*MockClock) Since

func (c *MockClock) Since(t time.Time) time.Duration

Returns the time elapsed since the fake current time.

func (*MockClock) Sleep

func (c *MockClock) Sleep(d time.Duration)

func (*MockClock) WakeupsCount

func (c *MockClock) WakeupsCount() int

Jump to

Keyboard shortcuts

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