timeutil

package
v0.0.0-...-fb1bee7 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignTime

func AlignTime(tm time.Time, interval time.Duration) time.Time

func FormatDuration

func FormatDuration(d time.Duration) string

func ParseDurationWithInt32

func ParseDurationWithInt32(val int32, defaultDuration time.Duration) time.Duration

func ParseDurationWithString

func ParseDurationWithString(text string, defaultDuration time.Duration) time.Duration

func ParseWeekday

func ParseWeekday(date time.Time) string

func RandomDuration

func RandomDuration(max time.Duration) time.Duration

func YearWeek

func YearWeek(t time.Time) int

Types

type AlignedTicker

type AlignedTicker struct {
	// contains filtered or unexported fields
}

AlignedTicker delivers ticks at aligned times plus an optional jitter. Each tick is realigned to avoid drift and handle changes to the system clock.

The ticks may have an jitter duration applied to them as an random offset to the interval. However the overall pace of is that of the interval, so on average you will have one collection each interval.

The first tick is emitted at the next alignment.

Ticks are dropped for slow consumers.

The implementation currently does not recalculate until the next tick with no maximum sleep, when using large intervals alignment is not corrected until the next tick.

func NewAlignedTicker

func NewAlignedTicker(now time.Time, interval, jitter, offset time.Duration) *AlignedTicker

func (*AlignedTicker) Elapsed

func (t *AlignedTicker) Elapsed() <-chan time.Time

func (*AlignedTicker) Stop

func (t *AlignedTicker) Stop()

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type RollingTicker

type RollingTicker struct {
	// contains filtered or unexported fields
}

RollingTicker delivers ticks at regular but unaligned intervals.

Because the next interval is scheduled based on the interval + jitter, you are guaranteed at least interval seconds without missing a tick and ticks will be evenly scheduled over time.

On average you will have one collection each interval + (jitter/2).

The first tick is emitted after interval+jitter seconds.

Ticks are dropped for slow consumers.

func NewRollingTicker

func NewRollingTicker(interval, jitter time.Duration) *RollingTicker

func (*RollingTicker) Elapsed

func (t *RollingTicker) Elapsed() <-chan time.Time

func (*RollingTicker) Stop

func (t *RollingTicker) Stop()

type UnalignedTicker

type UnalignedTicker struct {
	// contains filtered or unexported fields
}

UnalignedTicker delivers ticks at regular but unaligned intervals. No effort is made to avoid drift.

The ticks may have an jitter duration applied to them as an random offset to the interval. However the overall pace of is that of the interval, so on average you will have one collection each interval.

The first tick is emitted immediately.

Ticks are dropped for slow consumers.

func NewUnalignedTicker

func NewUnalignedTicker(interval, jitter, offset time.Duration) *UnalignedTicker

func (*UnalignedTicker) Elapsed

func (t *UnalignedTicker) Elapsed() <-chan time.Time

func (*UnalignedTicker) InjectTick

func (t *UnalignedTicker) InjectTick()

func (*UnalignedTicker) Stop

func (t *UnalignedTicker) Stop()

Jump to

Keyboard shortcuts

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