utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrEndBeforeStart is the error message for when a TimeInterval's end time
	// would be before its start.
	ErrEndBeforeStart = "end time before start time"
)

Variables

This section is empty.

Functions

func IsIn

func IsIn(s string, arr []string) bool

func ParseUTCTime

func ParseUTCTime(s string) (time.Time, error)

ParseUTCTime parses a string-represented time of the format 2006-01-02T15:04:05Z07:00

func SetupConfigFile

func SetupConfigFile() error

SetupConfigFile defines the settings for the configuration file support.

func ValidateGroups

func ValidateGroups(groupID, totalGroupsNum uint) error

ValidateGroups checks validity of combination groupID and totalGroups

Types

type TimeInterval

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

TimeInterval represents an interval of time in UTC. That is, regardless of what timezone(s) are used for the beginning and end times, they will be converted to UTC and methods will return them as such.

func NewTimeInterval

func NewTimeInterval(start, end time.Time) (*TimeInterval, error)

NewTimeInterval creates a new TimeInterval for a given start and end. If end is a time.Time before start, then an error is returned.

func (*TimeInterval) Duration

func (ti *TimeInterval) Duration() time.Duration

Duration returns the time.Duration of the TimeInterval.

func (*TimeInterval) End

func (ti *TimeInterval) End() time.Time

End returns the starting time in UTC.

func (*TimeInterval) EndString

func (ti *TimeInterval) EndString() string

EndString formats the end of the TimeInterval according to RFC3339.

func (*TimeInterval) EndUnixMillis

func (ti *TimeInterval) EndUnixMillis() int64

EndUnixMillis returns the end time as milliseconds.

func (*TimeInterval) EndUnixNano

func (ti *TimeInterval) EndUnixNano() int64

EndUnixNano returns the end time as nanoseconds.

func (*TimeInterval) MustRandWindow

func (ti *TimeInterval) MustRandWindow(window time.Duration) *TimeInterval

MustRandWindow is the form of RandWindow that cannot error; if it does error, it causes a panic.

func (*TimeInterval) Overlap

func (ti *TimeInterval) Overlap(other *TimeInterval) bool

Overlap detects whether the given TimeInterval overlaps with this TimeInterval, assuming an inclusive start boundary and exclusive end boundary.

func (*TimeInterval) RandWindow

func (ti *TimeInterval) RandWindow(window time.Duration) (*TimeInterval, error)

RandWindow creates a TimeInterval of duration `window` at a uniformly-random start time within the time period represented by this TimeInterval.

func (*TimeInterval) Start

func (ti *TimeInterval) Start() time.Time

Start returns the starting time in UTC.

func (*TimeInterval) StartString

func (ti *TimeInterval) StartString() string

StartString formats the start of the TimeInterval according to RFC3339.

func (*TimeInterval) StartUnixMillis

func (ti *TimeInterval) StartUnixMillis() int64

StartUnixMillis returns the start time as milliseconds.

func (*TimeInterval) StartUnixNano

func (ti *TimeInterval) StartUnixNano() int64

StartUnixNano returns the start time as nanoseconds.

Jump to

Keyboard shortcuts

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