timeutil

package
v0.0.0-...-6244b48 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SecsPerMin expresses the amount of seconds in a minute
	SecsPerMin = 60.0

	// SecsPerHour expresses the amount of seconds in a minute
	SecsPerHour = 3600.0

	// SecsPerDay expressed the amount of seconds in a day
	SecsPerDay = 86400.0

	// MinsPerHour expresses the amount of minutes in an hour
	MinsPerHour = 60.0

	// MinsPerDay expresses the amount of minutes in a day
	MinsPerDay = 1440.0

	// HoursPerDay expresses the amount of hours in a day
	HoursPerDay = 24.0

	// HoursPerMonth expresses the amount of hours in a month
	HoursPerMonth = 730.0

	// DaysPerMonth expresses the amount of days in a month
	DaysPerMonth = 30.42

	// Day expresses 24 hours
	Day = time.Hour * 24.0

	Week = Day * 7.0
)

Variables

This section is empty.

Functions

func CleanDurationString

func CleanDurationString(duration string) string

CleanDurationString removes prometheus formatted prefix "offset " allong with leading a trailing whitespace from duration string, leaving behind a string with format [0-9+](s|m|d|h)

func DurationOffsetStrings

func DurationOffsetStrings(duration, offset time.Duration) (string, string)

DurationOffsetStrings converts a (duration, offset) pair to Prometheus- compatible strings in terms of days, hours, minutes, or seconds.

func DurationString

func DurationString(duration time.Duration) string

DurationString converts a duration to a Prometheus-compatible string in terms of days, hours, minutes, or seconds.

func DurationToPromOffsetString

func DurationToPromOffsetString(duration time.Duration) string

DurationToPromOffsetString returns a Prometheus formatted string with leading offset or empty string if given a negative duration

func EarlierOf

func EarlierOf(timeOne, timeTwo time.Time) time.Time

EarlierOf returns the second time passed in if both are equal

func FormatDurationStringDaysToHours

func FormatDurationStringDaysToHours(param string) (string, error)

FormatDurationStringDaysToHours converts string from format [0-9+]d to [0-9+]h

func FormatStoreResolution

func FormatStoreResolution(dur time.Duration) string

FormatStoreResolution provides a clean notation for ETL store resolutions. e.g. daily => 1d; hourly => 1h

func LaterOf

func LaterOf(timeOne, timeTwo time.Time) time.Time

LaterOf returns the second time passed in if both are equal

func ParseDuration

func ParseDuration(duration string) (time.Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d"

func ParseTimeRange

func ParseTimeRange(duration, offset time.Duration) (time.Time, time.Time)

ParseTimeRange returns a start and end time, respectively, which are converted from a duration and offset, defined as strings with Prometheus-style syntax.

func ParseUTCOffset

func ParseUTCOffset(offsetStr string) (time.Duration, error)

ParseUTCOffset attempts to parse a UTC offset string. Returns a valid time.Duration if error is nil.

func RoundToStartOfFollowingWeek

func RoundToStartOfFollowingWeek(t time.Time) time.Time

RoundToStartOfFollowingWeek creates a new time.Time for the following Sunday 00:00 UTC

func RoundToStartOfWeek

func RoundToStartOfWeek(t time.Time) time.Time

RoundToStartOfWeek creates a new time.Time for the preceding Sunday 00:00 UTC

Types

type JobTicker

type JobTicker struct {
	Ch <-chan time.Time
	// contains filtered or unexported fields
}

JobTicker is a ticker used to synchronize the next run of a repeating process. The designated use-case is for infinitely-looping selects, where a timeout or an exit channel might cancel the process, but otherwise the intent is to wait at the select for some amount of time until the next run. This differs from a standard ticker, which ticks without waiting and drops any missed ticks; rather, this ticker must be kicked off manually for each tick, so that after the current run of the job completes, the timer starts again.

func NewJobTicker

func NewJobTicker() *JobTicker

NewJobTicker instantiates a new JobTicker.

func (*JobTicker) Close

func (jt *JobTicker) Close()

Close closes the JobTicker channels

func (*JobTicker) TickAt

func (jt *JobTicker) TickAt(t time.Time)

TickAt schedules the next tick of the ticker for the given time in the future. If the time is not in the future, the ticker will tick immediately.

func (*JobTicker) TickIn

func (jt *JobTicker) TickIn(d time.Duration)

TickIn schedules the next tick of the ticker for the given duration into the future. If the duration is less than or equal to zero, the ticker will tick immediately.

type ProfileDataSeries

type ProfileDataSeries struct {
	Name   string
	Series []*ProfileDatum
}

func NewProfileDataSeries

func NewProfileDataSeries(name string, steps int) *ProfileDataSeries

func (*ProfileDataSeries) Start

func (pds *ProfileDataSeries) Start()

func (*ProfileDataSeries) Step

func (pds *ProfileDataSeries) Step(name string)

func (*ProfileDataSeries) Stop

func (pds *ProfileDataSeries) Stop()

func (*ProfileDataSeries) String

func (pds *ProfileDataSeries) String() string

type ProfileDatum

type ProfileDatum struct {
	Name string
	Time time.Time
}

Jump to

Keyboard shortcuts

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