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
68// Set sets the Clock to a clock.Mock at the given time.Time
69func (c *Clock) Set(t time.Time) {
71 c.mock = clockapi.NewMock()
76// Add moves clock forward time.Duration if it is mocked. It will error
77// if the clock is not mocked.
78func (c *Clock) Add(d time.Duration) error {
80 return errors.New("clock not mocked")
86// Reset removes local clock.Mock. Returns any existing Mock if set in case
87// lingering time operations are attached to it.
88func (c *Clock) Reset() *clockapi.Mock {
94func (c *Clock) After(d time.Duration) <-chan time.Time {
97 return globalClock.After(d)
102func (c *Clock) AfterFunc(d time.Duration, f func()) *clockapi.Timer {
105 return globalClock.AfterFunc(d, f)
107 return m.AfterFunc(d, f)
110func (c *Clock) Now() time.Time {
113 return globalClock.Now()
118func (c *Clock) Since(t time.Time) time.Duration {
121 return globalClock.Since(t)
126func (c *Clock) Sleep(d time.Duration) {
135func (c *Clock) Tick(d time.Duration) <-chan time.Time {
138 return globalClock.Tick(d)
143func (c *Clock) Ticker(d time.Duration) *clockapi.Ticker {
146 return globalClock.Ticker(d)
151func (c *Clock) Timer(d time.Duration) *clockapi.Timer {
154 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