timeutil

package
v0.92.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApproximateBins added in v0.58.0

func ApproximateBins(start, end time.Time, tg TimeGrain) int

func OffsetTime added in v0.60.7

func OffsetTime(tm time.Time, tg TimeGrain, n int, tz *time.Location) time.Time

func TimeGrainBase

func TimeGrainBase(tg runtimev1.TimeGrain) (runtimev1.TimeGrain, int)

TimeGrainBase returns the base unit of an API grain and the number of those units it spans. Standard grains return themselves and 1.

func TimeGrainToAPI added in v0.74.0

func TimeGrainToAPI(tg TimeGrain) runtimev1.TimeGrain

func TruncateTime

func TruncateTime(tm time.Time, tg TimeGrain, tz *time.Location, firstDay, firstMonth int) time.Time

func WallClockBucketStart

func WallClockBucketStart(tm time.Time, hours int, tz *time.Location) time.Time

WallClockBucketStart returns the local date and time in tz at which the bucket of an hour multiple that contains tm starts, as a UTC time that holds that wall-clock time. Dialects that step hour multiples on the local clock start their spines from it. It is earlier than the local time of TruncateTime for a bucket that starts in a DST gap, since TruncateTime moves that start past the gap.

Types

type TimeGrain

type TimeGrain int

TimeGrain is extension of std time package with Week and Quarter added

const (
	TimeGrainUnspecified TimeGrain = iota
	TimeGrainMillisecond
	TimeGrainSecond
	TimeGrainMinute
	TimeGrainHour
	TimeGrainDay
	TimeGrainWeek
	TimeGrainMonth
	TimeGrainQuarter
	TimeGrainYear
	// Multiples of a base grain.
	// They are only used to bucket time series.
	// Their numeric values are not the grain order: use Compare to order grains.
	TimeGrain5Minute
	TimeGrain10Minute
	TimeGrain15Minute
	TimeGrain30Minute
	TimeGrain2Hour
	TimeGrain3Hour
	TimeGrain4Hour
	TimeGrain6Hour
	TimeGrain8Hour
	TimeGrain12Hour
)

func TimeGrainFromAPI added in v0.74.0

func TimeGrainFromAPI(tg runtimev1.TimeGrain) TimeGrain

func (TimeGrain) ApproxDuration

func (tg TimeGrain) ApproxDuration() time.Duration

ApproxDuration returns the nominal length of a grain. Calendar grains use fixed approximations, which is enough to order grains and estimate bin counts.

func (TimeGrain) Base

func (tg TimeGrain) Base() (TimeGrain, int)

Base returns the unit a grain is a multiple of and the factor. Standard grains return themselves and 1.

func (TimeGrain) Compare

func (tg TimeGrain) Compare(other TimeGrain) int

Compare orders grains from fine to coarse by their approximate duration. It returns a negative number when tg is finer than other, zero when they are equal, and a positive number when tg is coarser.

Jump to

Keyboard shortcuts

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