godropbox: github.com/dropbox/godropbox/time2 Index | Files

package time2

import "github.com/dropbox/godropbox/time2"

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


Package Files

clock.go doc.go mock_clock.go time2.go


var DefaultClock = &realClock{}

func NowFloat Uses

func NowFloat() float64

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

func TimeToFloat Uses

func TimeToFloat(t time.Time) float64

Convert Time to epoch seconds with subsecond precision.

type Clock Uses

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 Uses

type MockClock struct {
    // contains filtered or unexported fields

A fake clock useful for testing timing.

func NewMockClock Uses

func NewMockClock(now time.Time) *MockClock

func (*MockClock) Advance Uses

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

Advances the mock clock by the specified duration.

func (*MockClock) AdvanceTo Uses

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

Advance to a specific time.

func (*MockClock) AdvanceToNextWakeup Uses

func (c *MockClock) AdvanceToNextWakeup()

func (*MockClock) After Uses

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

func (*MockClock) NextWakeupTime Uses

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

func (*MockClock) Now Uses

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

Returns the fake current time.

func (*MockClock) NowFloat Uses

func (c *MockClock) NowFloat() float64

Returns the fake current time in epoch seconds.

func (*MockClock) Set Uses

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 Uses

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

func (*MockClock) Since Uses

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

Returns the time elapsed since the fake current time.

func (*MockClock) Sleep Uses

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

func (*MockClock) WakeupsCount Uses

func (c *MockClock) WakeupsCount() int

Package time2 imports 4 packages (graph). Updated 2017-07-28. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).