time_span

package
v0.0.0-...-f1bff1d Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxTime

func MaxTime(a time.Time, b time.Time) time.Time

Return the later of the two times

func MinTime

func MinTime(a time.Time, b time.Time) time.Time

Return the earlier of the two times

Types

type BaseInterval

type BaseInterval struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

type ClosedInterval

type ClosedInterval BaseInterval

A closed interval of time. Empty intervals are represented by having Start > End.

func NewClosedInterval

func NewClosedInterval(start time.Time, end time.Time) ClosedInterval

func (ClosedInterval) Combine

Return the smallest interval containing the start and end points of the two intervals, even if they are empty. That is, the maximum of end times and the minimum of start times.

func (ClosedInterval) Duration

func (span ClosedInterval) Duration() time.Duration

func (ClosedInterval) Empty

func (span ClosedInterval) Empty() bool

func (ClosedInterval) Expand

func (t ClosedInterval) Expand(delta time.Duration) ClosedInterval

Extend an interval by "delta" in each direction (thus it gets 2*delta longer.) If it was empty, expand around the start point.

func (ClosedInterval) ExpandToIncludeTime

func (interval ClosedInterval) ExpandToIncludeTime(t time.Time) ClosedInterval

Extend an interval to include the given time. If the interval is empty, then the result will be the singleton interval containing the given time.

func (ClosedInterval) Includes

func (span ClosedInterval) Includes(query time.Time) bool

Determines whether the span includes the given query.

func (ClosedInterval) Intersect

Return the portion of this interval that lies entirely within another closed interval. Intersection with an open interval or half-open interval is not provided because the result might either be open or closed, and that's a pain to deal with (the point of splitting them out was to stop confusing the type of interval involved and be able to statically type-check it!)

func (ClosedInterval) Overlaps

func (t1 ClosedInterval) Overlaps(t2 ClosedInterval) bool

Determine whether there is an overlap between two closed intervals

type HalfOpenInterval

type HalfOpenInterval BaseInterval

An half-open interval [start,end) Empty intervals are represented by having Start >= End.

func NewHalfOpenInterval

func NewHalfOpenInterval(start time.Time, end time.Time) HalfOpenInterval

func (HalfOpenInterval) Combine

Return the smallest interval containing the start and end points of the two intervals, even if they are empty. That is, the maximum of end times and the minimum of start times,

The important use case for handling events is that the zero-length interval [a,a) can be combined with a non-empty interval [b,c) not including a to produce [a,c) or [b,a).

func (HalfOpenInterval) Contains

func (t1 HalfOpenInterval) Contains(t2 HalfOpenInterval) bool

Returns true if t2 is entirely contained within t1 (i.e., a subset)

func (HalfOpenInterval) Duration

func (span HalfOpenInterval) Duration() time.Duration

func (HalfOpenInterval) Empty

func (span HalfOpenInterval) Empty() bool

func (HalfOpenInterval) Expand

Extend an interval by "delta" in each direction (thus it gets 2*delta longer.) If empty, return an interval of size 2 * delta around the start point.

func (HalfOpenInterval) Includes

func (span HalfOpenInterval) Includes(query time.Time) bool

Determines whether the interval includes the given query.

func (HalfOpenInterval) Intersect

Return the intersection of two half-open intervals. (i.e., trim this interval to lie entirely within another.) May result in an interval with end <= start, which should be treated as empty.

func (HalfOpenInterval) Overlaps

func (t1 HalfOpenInterval) Overlaps(t2 HalfOpenInterval) bool

type TimeSpan

type TimeSpan = HalfOpenInterval

func NewTimeSpan

func NewTimeSpan(start time.Time, end time.Time) *TimeSpan

Jump to

Keyboard shortcuts

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