gtime

package
v0.244.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 42

Documentation

Overview

gtime provides utilities for parsing time, time ranges and time durations (intervals).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatInterval added in v0.205.0

func FormatInterval(inter time.Duration) string

FormatInterval converts a duration into the units that Grafana uses

func GetIntervalFrom added in v0.207.0

func GetIntervalFrom(dsInterval, queryInterval string, queryIntervalMS int64, defaultInterval time.Duration) (time.Duration, error)

GetIntervalFrom returns the minimum interval. dsInterval is the string representation of data source min interval, if configured. queryInterval is the string representation of query interval (min interval), e.g. "10ms" or "10s". queryIntervalMS is a pre-calculated numeric representation of the query interval in milliseconds.

func ParseDuration

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

ParseDuration parses a duration with support for all units that Grafana uses. Durations are independent of wall time.

func ParseInterval

func ParseInterval(inp string) (time.Duration, error)

ParseInterval parses an interval with support for all units that Grafana uses. An interval is relative to the current wall time.

func ParseIntervalStringToTimeDuration added in v0.207.0

func ParseIntervalStringToTimeDuration(interval string) (time.Duration, error)

ParseIntervalStringToTimeDuration converts a string representation of a expected (i.e. 1m30s) to time.Duration this method copied from grafana/grafana/pkg/tsdb/intervalv2.go

func RoundInterval added in v0.208.0

func RoundInterval(interval time.Duration) time.Duration

RoundInterval returns a predetermined, lower and rounder duration than the given

Types

type TimeRange added in v0.234.0

type TimeRange struct {
	// From the raw start time in time range.
	From string

	// To the raw end time in time range.
	To string

	// Now the current time. Should normally only change in tests.
	Now time.Time
}

func NewTimeRange added in v0.234.0

func NewTimeRange(from, to string) TimeRange

NewTimeRange creates a new TimeRange of From and To.

func (TimeRange) GetFromAsMsEpoch added in v0.234.0

func (tr TimeRange) GetFromAsMsEpoch() int64

GetFromAsMsEpoch parses start of time range and returns result in milliseconds epoch or the Unix epoch 0 equivalent if it fails.

func (TimeRange) GetFromAsSecondsEpoch added in v0.234.0

func (tr TimeRange) GetFromAsSecondsEpoch() int64

GetFromAsSecondsEpoch parses start of time range and returns result in seconds epoch or the Unix epoch 0 equivalent if it fails.

func (TimeRange) GetFromAsTimeUTC added in v0.234.0

func (tr TimeRange) GetFromAsTimeUTC() time.Time

GetFromAsTimeUTC parses start of time range and returns result as time.Time in UTC timezone or the Unix epoch 0 equivalent if it fails.

func (TimeRange) GetToAsMsEpoch added in v0.234.0

func (tr TimeRange) GetToAsMsEpoch() int64

GetToAsMsEpoch parses end of time range and returns result in milliseconds epoch or the Unix epoch 0 equivalent if it fails.

func (TimeRange) GetToAsSecondsEpoch added in v0.234.0

func (tr TimeRange) GetToAsSecondsEpoch() int64

GetToAsSecondsEpoch parses end of time range and returns result in seconds epoch or the Unix epoch 0 equivalent if it fails.

func (TimeRange) GetToAsTimeUTC added in v0.234.0

func (tr TimeRange) GetToAsTimeUTC() time.Time

GetToAsTimeUTC parses end of time range and returns result as time.Time in UTC timezone or the Unix epoch 0 equivalent if it fails.

func (TimeRange) MustGetFrom added in v0.234.0

func (tr TimeRange) MustGetFrom() time.Time

MustGetFrom parses start of time range and returns result as time.Time or the Unix epoch 0 equivalent if it fails.

func (TimeRange) MustGetTo added in v0.234.0

func (tr TimeRange) MustGetTo() time.Time

MustGetTo parses end of time range and returns result as time.Time or the Unix epoch 0 equivalent if it fails.

func (TimeRange) ParseFrom added in v0.234.0

func (tr TimeRange) ParseFrom(options ...TimeRangeOption) (time.Time, error)

ParseFrom parses start of time range with optional TimeRangeOption's and returns equivalent or an error.

func (TimeRange) ParseTo added in v0.234.0

func (tr TimeRange) ParseTo(options ...TimeRangeOption) (time.Time, error)

ParseTo parses end of time range with optional TimeRangeOption's and returns time.Time or an error.

type TimeRangeOption added in v0.234.0

type TimeRangeOption func(timeRange parsableTime) parsableTime

TimeRangeOption option for how to parse time ranges.

func WithFiscalStartMonth added in v0.234.0

func WithFiscalStartMonth(month time.Month) TimeRangeOption

WithLocation time range option to set the start month of fiscal year.

func WithLocation added in v0.234.0

func WithLocation(loc *time.Location) TimeRangeOption

WithLocation time range option uses the given location loc as the timezone of the time range if unspecified.

func WithNow added in v0.234.0

func WithNow(t time.Time) TimeRangeOption

WithNow time range option to set the current time as t.

func WithRoundUp added in v0.234.0

func WithRoundUp() TimeRangeOption

WithRoundUp time range option to set the rounding of time to the end of the period instead of the beginning.

func WithWeekstart added in v0.234.0

func WithWeekstart(weekday time.Weekday) TimeRangeOption

WithWeekstart time range option to set given weekday as the start of the week.

Jump to

Keyboard shortcuts

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