tstime: add Since method (#8622)

Updates #8463

Signed-off-by: Claire Wang <claire@tailscale.com>
This commit is contained in:
Claire Wang
2023-07-14 16:50:17 -04:00
committed by GitHub
parent 60e5761d60
commit 0573f6e953
3 changed files with 57 additions and 0 deletions

View File

@@ -84,6 +84,9 @@ type Clock interface {
// by this Clock. When the ticker expires, it will call the provided func.
// It follows the semantics of time.AfterFunc.
AfterFunc(d time.Duration, f func()) TimerController
// Since returns the time elapsed since t.
// It follows the semantics of time.Since.
Since(t time.Time) time.Duration
}
// TickerController offers the receivers of a time.Ticker to ensure
@@ -135,3 +138,8 @@ func (StdClock) NewTicker(d time.Duration) (TickerController, <-chan time.Time)
func (StdClock) AfterFunc(d time.Duration, f func()) TimerController {
return time.AfterFunc(d, f)
}
// Since calls time.Since.
func (StdClock) Since(t time.Time) time.Duration {
return time.Since(t)
}