8 clockapi "github.com/benbjohnson/clock"
12 globalClock = clockapi.New()
16// Set the global clock to a clockapi.Mock with the given time.Time
17func Set(t time.Time) {
20 mock, ok := globalClock.(*clockapi.Mock)
22 mock = clockapi.NewMock()
28// Add moves the mocked global clock forward the given duration. It will error
29// if the global clock is not mocked.
30func Add(d time.Duration) error {
33 mock, ok := globalClock.(*clockapi.Mock)
35 return errors.New("time not mocked")
41// Reset sets the global clock to a pure time implementation. Returns any
42// existing Mock if set in case lingering time operations are attached to it.
43func Reset() *clockapi.Mock {
46 existing := globalClock
47 globalClock = clockapi.New()
49 mock, ok := existing.(*clockapi.Mock)
56// Clock is a non-package level wrapper around time that supports stubbing.
57// It will use its localized stubs (allowing for parallelized unit tests
58// where package level stubbing would cause issues). It falls back to any
59// package level time stubs for non-parallel, cross-package integration
62// If nothing is stubbed, it defaults to default time behavior in the time
69// Set sets the Clock to a clock.Mock at the given time.Time
70func (c *Clock) Set(t time.Time) {
74 c.mock = clockapi.NewMock()
79// Add moves clock forward time.Duration if it is mocked. It will error
80// if the clock is not mocked.
81func (c *Clock) Add(d time.Duration) error {
85 return errors.New("clock not mocked")
91// Reset removes local clock.Mock. Returns any existing Mock if set in case
92// lingering time operations are attached to it.
93func (c *Clock) Reset() *clockapi.Mock {
101func (c *Clock) After(d time.Duration) <-chan time.Time {
104 return globalClock.After(d)
109func (c *Clock) AfterFunc(d time.Duration, f func()) *clockapi.Timer {
112 return globalClock.AfterFunc(d, f)
114 return m.AfterFunc(d, f)
117func (c *Clock) Now() time.Time {
120 return globalClock.Now()
125func (c *Clock) Since(t time.Time) time.Duration {
128 return globalClock.Since(t)
133func (c *Clock) Sleep(d time.Duration) {
142func (c *Clock) Tick(d time.Duration) <-chan time.Time {
145 return globalClock.Tick(d)
150func (c *Clock) Ticker(d time.Duration) *clockapi.Ticker {
153 return globalClock.Ticker(d)
158func (c *Clock) Timer(d time.Duration) *clockapi.Timer {
161 return globalClock.Timer(d)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list