Documentation ¶
Overview ¶
gtime provides utilities for parsing time, time ranges and time durations (intervals).
Index ¶
- func FormatInterval(inter time.Duration) string
- func GetIntervalFrom(dsInterval, queryInterval string, queryIntervalMS int64, ...) (time.Duration, error)
- func ParseDuration(inp string) (time.Duration, error)
- func ParseInterval(inp string) (time.Duration, error)
- func ParseIntervalStringToTimeDuration(interval string) (time.Duration, error)
- func RoundInterval(interval time.Duration) time.Duration
- type TimeRange
- func (tr TimeRange) GetFromAsMsEpoch() int64
- func (tr TimeRange) GetFromAsSecondsEpoch() int64
- func (tr TimeRange) GetFromAsTimeUTC() time.Time
- func (tr TimeRange) GetToAsMsEpoch() int64
- func (tr TimeRange) GetToAsSecondsEpoch() int64
- func (tr TimeRange) GetToAsTimeUTC() time.Time
- func (tr TimeRange) MustGetFrom() time.Time
- func (tr TimeRange) MustGetTo() time.Time
- func (tr TimeRange) ParseFrom(options ...TimeRangeOption) (time.Time, error)
- func (tr TimeRange) ParseTo(options ...TimeRangeOption) (time.Time, error)
- type TimeRangeOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatInterval ¶ added in v0.205.0
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 ¶
ParseDuration parses a duration with support for all units that Grafana uses. Durations are independent of wall time.
func ParseInterval ¶
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
ParseIntervalStringToTimeDuration converts a string representation of a expected (i.e. 1m30s) to time.Duration this method copied from grafana/grafana/pkg/tsdb/intervalv2.go
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
NewTimeRange creates a new TimeRange of From and To.
func (TimeRange) GetFromAsMsEpoch ¶ added in v0.234.0
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
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
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
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
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
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
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
MustGetTo parses end of time range and returns result as time.Time or the Unix epoch 0 equivalent if it fails.
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.