tstime
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package tstime defines Tailscale-specific time utilities.
Index¶
- func Parse3339(s string) (time.Time, error)
- func Parse3339B(b []byte) (time.Time, error)
- func ParseDuration(s string) (time.Duration, error)
- func RandomDurationBetween(min, max time.Duration) time.Duration
- func Sleep(ctx context.Context, d time.Duration) bool
- type Clock
- type DefaultClock
- func (c DefaultClock) AfterFunc(d time.Duration, f func()) TimerController
- func (c DefaultClock) NewTicker(d time.Duration) (TickerController, <-chan time.Time)
- func (c DefaultClock) NewTimer(d time.Duration) (TimerController, <-chan time.Time)
- func (c DefaultClock) Now() time.Time
- func (c DefaultClock) Since(t time.Time) time.Duration
- type GoDuration
- type StdClock
- func (StdClock) AfterFunc(d time.Duration, f func()) TimerController
- func (StdClock) NewTicker(d time.Duration) (TickerController, <-chan time.Time)
- func (StdClock) NewTimer(d time.Duration) (TimerController, <-chan time.Time)
- func (StdClock) Now() time.Time
- func (StdClock) Since(t time.Time) time.Duration
- type TickerController
- type TimerController
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcParse3339B¶added inv1.4.0
Parse3339B is Parse3339 but for byte slices.
funcParseDuration¶added inv1.32.0
ParseDuration is more expressive thantime.ParseDuration,also accepting 'd' (days) and 'w' (weeks) literals.
funcRandomDurationBetween¶added inv1.4.0
RandomDurationBetween returns a random duration in range [min,max).If panics if max < min.
Types¶
typeClock¶added inv1.46.0
type Clock interface {// Now returns the current time, as in time.Now.Now()time.Time// NewTimer returns a timer whose notion of the current time is controlled// by this Clock. It follows the semantics of time.NewTimer as closely as// possible but is adapted to return an interface, so the channel needs to// be returned as well.NewTimer(dtime.Duration) (TimerController, <-chantime.Time)// NewTicker returns a ticker whose notion of the current time is controlled// by this Clock. It follows the semantics of time.NewTicker as closely as// possible but is adapted to return an interface, so the channel needs to// be returned as well.NewTicker(dtime.Duration) (TickerController, <-chantime.Time)// AfterFunc returns a ticker whose notion of the current time is controlled// by this Clock. When the ticker expires, it will call the provided func.// It follows the semantics of time.AfterFunc.AfterFunc(dtime.Duration, f func())TimerController// Since returns the time elapsed since t.// It follows the semantics of time.Since.Since(ttime.Time)time.Duration}Clock offers a subset of the functionality from the std/time package.Normally, applications will use the StdClock implementation that calls theappropriate std/time exported funcs. The advantage of using Clock is thattests can substitute a different implementation, allowing the test to controltime precisely, something required for certain types of tests to be possibleat all, speeds up execution by not needing to sleep, and can dramaticallyreduce the risk of flakes due to tests executing too slowly or quickly.
typeDefaultClock¶added inv1.52.0
type DefaultClock struct{Clock }DefaultClock is a wrapper around a Clock.It uses StdClock by default if Clock is nil.
func (DefaultClock)AfterFunc¶added inv1.52.0
func (cDefaultClock) AfterFunc(dtime.Duration, f func())TimerController
func (DefaultClock)NewTicker¶added inv1.52.0
func (cDefaultClock) NewTicker(dtime.Duration) (TickerController, <-chantime.Time)
func (DefaultClock)NewTimer¶added inv1.52.0
func (cDefaultClock) NewTimer(dtime.Duration) (TimerController, <-chantime.Time)
func (DefaultClock)Now¶added inv1.52.0
func (cDefaultClock) Now()time.Time
typeGoDuration¶added inv1.84.0
GoDuration is atime.Duration but JSON serializes withtime.Duration.String.
Note that this format is specific to Go and non-standard,but excels in being most humanly readable compared to alternatives.The wider industry still lacks consensus for the representationof a time duration in humanly-readable text.Seehttps://go.dev/issue/71631 for more discussion.
Regardless of how the industry evolves into the future,this type explicitly uses the Go format.
func (GoDuration)AppendText¶added inv1.84.0
func (dGoDuration) AppendText(b []byte) ([]byte,error)
func (GoDuration)MarshalText¶added inv1.84.0
func (dGoDuration) MarshalText() ([]byte,error)
func (*GoDuration)UnmarshalText¶added inv1.84.0
func (d *GoDuration) UnmarshalText(b []byte)error
typeStdClock¶added inv1.46.0
type StdClock struct{}StdClock is a simple implementation of Clock using the relevant funcs in thestd/time package.
func (StdClock)AfterFunc¶added inv1.46.0
func (StdClock) AfterFunc(dtime.Duration, f func())TimerController
AfterFunc calls time.AfterFunc.
func (StdClock)NewTicker¶added inv1.46.0
NewTicker calls time.NewTicker. As an interface does not allow for structmembers and other packages cannot add receivers to another package, thechannel is also returned because it would be otherwise inaccessible.
typeTickerController¶added inv1.46.0
type TickerController interface {// Reset follows the same semantics as with time.Ticker.Reset.Reset(dtime.Duration)// Stop follows the same semantics as with time.Ticker.Stop.Stop()}TickerController offers the receivers of a time.Ticker to ensurecompatibility with standard timers, but allows for the option of substitutinga standard timer with something else for testing purposes.
typeTimerController¶added inv1.46.0
type TimerController interface {// Reset follows the same semantics as with time.Timer.Reset.Reset(dtime.Duration)bool// Stop follows the same semantics as with time.Timer.Stop.Stop()bool}TimerController offers the receivers of a time.Timer to ensurecompatibility with standard timers, but allows for the option of substitutinga standard timer with something else for testing purposes.