1
0
times/lib.go

44 lines
672 B
Go

package times
import "time"
type Clock interface {
Now() time.Time
After(time.Duration) <-chan time.Time
}
type TestClock struct{
clock test
}
func Sys() Clock {
return sys{}
}
func Test() TestClock {
var zero time.Time
return TestFrom(zero)
}
func TestFrom(t time.Time) TestClock {
return TestClock{clock: makeTestClock(t)}
}
func (c TestClock) Now() time.Time {
return c.clock.now()
}
func (c TestClock) After(d time.Duration) <-chan time.Time {
return c.clock.after(d)
}
// negative pass not allowed
func (c TestClock) Pass(d time.Duration) {
c.clock.pass(d)
}
// backwards jump not allowed
func (c TestClock) Jump(t time.Time) {
c.clock.jump(t)
}