cstime

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTimeStrict

func ParseTimeStrict(layout, value string) (time.Time, error)

ParseTimeStrict parses a formatted string and returns the time value it represents. The output is identical to time.Parse except it returns an error for strings that don't format to the input value.

An example where the output differs from time.Parse would be: parseTimeStrict("1/2/06", "11/31/15")

- time.Parse returns "2015-12-01 00:00:00 +0000 UTC"

- ParseTimeStrict returns an error

Types

type RandomTicker

type RandomTicker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

RandomTicker is similar to time.Ticker but ticks at random intervals between the min and max duration values (stored internally as int64 nanosecond counts).

func NewRandomTicker

func NewRandomTicker(min, max, durationKind time.Duration) *RandomTicker

NewRandomTicker returns a pointer to an initialized instance of the RandomTicker. Min and max are durations of the shortest and longest allowed ticks. Ticker will run in a goroutine until explicitly stopped. durationKind must be one of the following constants: time.Nanosecond, time.Microsecond, time.Millisecond, time.Second, time.Minute, time.Hour or it panics. AFAIK: It uses time.NewTimer under the hood which increases memory usage in tight loops a lot as the timer cannot be garbage collected.

func (*RandomTicker) NextInterval

func (rt *RandomTicker) NextInterval() time.Duration

NextInterval returns a random duration between max and min in the provided durationKind.

func (*RandomTicker) Stop

func (rt *RandomTicker) Stop()

Stop terminates the ticker goroutine and closes the C channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL