Movatterモバイル変換


[0]ホーム

URL:


tstime

package
v1.92.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:6Imported by:26

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package tstime defines Tailscale-specific time utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcParse3339

func Parse3339(sstring) (time.Time,error)

Parse3339 is a wrapper around time.Parse(time.RFC3339, s).

funcParse3339Badded inv1.4.0

func Parse3339B(b []byte) (time.Time,error)

Parse3339B is Parse3339 but for byte slices.

funcParseDurationadded inv1.32.0

func ParseDuration(sstring) (time.Duration,error)

ParseDuration is more expressive thantime.ParseDuration,also accepting 'd' (days) and 'w' (weeks) literals.

funcRandomDurationBetweenadded inv1.4.0

func RandomDurationBetween(min, maxtime.Duration)time.Duration

RandomDurationBetween returns a random duration in range [min,max).If panics if max < min.

funcSleepadded inv1.38.0

func Sleep(ctxcontext.Context, dtime.Duration)bool

Sleep is liketime.Sleep but returns early upon context cancelation.It reports whether the full sleep duration was achieved.

Types

typeClockadded 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.

typeDefaultClockadded 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)AfterFuncadded inv1.52.0

func (cDefaultClock) AfterFunc(dtime.Duration, f func())TimerController

func (DefaultClock)NewTickeradded inv1.52.0

func (cDefaultClock) NewTicker(dtime.Duration) (TickerController, <-chantime.Time)

func (DefaultClock)NewTimeradded inv1.52.0

func (cDefaultClock) NewTimer(dtime.Duration) (TimerController, <-chantime.Time)

func (DefaultClock)Nowadded inv1.52.0

func (cDefaultClock) Now()time.Time

func (DefaultClock)Sinceadded inv1.52.0

typeGoDurationadded inv1.84.0

type GoDuration struct{time.Duration }

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)AppendTextadded inv1.84.0

func (dGoDuration) AppendText(b []byte) ([]byte,error)

func (GoDuration)MarshalTextadded inv1.84.0

func (dGoDuration) MarshalText() ([]byte,error)

func (*GoDuration)UnmarshalTextadded inv1.84.0

func (d *GoDuration) UnmarshalText(b []byte)error

typeStdClockadded inv1.46.0

type StdClock struct{}

StdClock is a simple implementation of Clock using the relevant funcs in thestd/time package.

func (StdClock)AfterFuncadded inv1.46.0

func (StdClock) AfterFunc(dtime.Duration, f func())TimerController

AfterFunc calls time.AfterFunc.

func (StdClock)NewTickeradded inv1.46.0

func (StdClock) NewTicker(dtime.Duration) (TickerController, <-chantime.Time)

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.

func (StdClock)NewTimeradded inv1.46.0

func (StdClock) NewTimer(dtime.Duration) (TimerController, <-chantime.Time)

NewTimer calls time.NewTimer. 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.

func (StdClock)Nowadded inv1.46.0

func (StdClock) Now()time.Time

Now calls time.Now.

func (StdClock)Sinceadded inv1.46.0

Since calls time.Since.

typeTickerControlleradded 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.

typeTimerControlleradded 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.

Source Files

View all Source files

Directories

PathSynopsis
Package mono provides fast monotonic time.
Package mono provides fast monotonic time.
Package rate provides a rate limiter.
Package rate provides a rate limiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp