Documentation ¶
Overview ¶
Package trn provides structures and methods to perform complex operations over time ranges.
Index ¶
- Constants
- type Error
- type Option
- type Range
- func Between(start, end time.Time, opts ...Option) (Range, error)
- func Intersection(ranges []Range) Range
- func MergeOverlappingRanges(ranges []Range) []Range
- func MustRange(r Range, err error) Range
- func MustRanges(r []Range, err error) []Range
- func New(start time.Time, duration time.Duration, opts ...Option) Range
- func (r Range) Contains(other Range) bool
- func (r Range) Duration() time.Duration
- func (r Range) Empty() bool
- func (r Range) End() time.Time
- func (r Range) Flip(ranges []Range) []Range
- func (r Range) Format(layout string) string
- func (r Range) GoString() string
- func (r Range) In(loc *time.Location) Range
- func (r Range) Split(duration time.Duration, interval time.Duration) ([]Range, error)
- func (r Range) Start() time.Time
- func (r Range) Stratify(duration time.Duration, interval time.Duration) ([]Range, error)
- func (r Range) String() string
- func (r Range) Truncate(bounds Range) Range
- func (r Range) UTC() Range
Constants ¶
const ( ErrStartAfterEnd = Error("trn: start time is later than the end") ErrZeroDurationInterval = Error("trn: cannot split with zero duration or interval") )
package errors
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range represents time slot with its own start and end time boundaries
func Between ¶
Between returns the new Range in the given time bounds. Range will use the location of the start timestamp. Returns ErrStartAfterEnd if the start time is later than the end.
func Intersection ¶
Intersection returns the date range, which is common for all the given ranges.
func MergeOverlappingRanges ¶
MergeOverlappingRanges looks in the ranges slice, seeks for overlapping ranges and merges such ranges into the one range.
func MustRange ¶ added in v0.3.0
MustRange is a helper that accepts the result of function, that returns a single range and panics, if err is returned.
func MustRanges ¶ added in v0.3.0
MustRanges is a helper that accepts the result of function, that returns ranges and panics, if err is returned.
func (Range) Flip ¶
Flip within the given period.
The boundaries of the given ranges are considered to be inclusive, means that the flipped ranges will start or end at the exact nanosecond where the boundary from the input starts or ends.
func (Range) Format ¶
Format returns the string representation of the time range with the given format.
func (Range) GoString ¶
GoString implements fmt.GoStringer and formats r to be printed in Go source code.
func (Range) Split ¶
Split the date range into smaller ranges, with fixed duration and with the given interval between the *end* of the one range and *start* of next range. In case if the last interval doesn't fit into the given duration, MustSplit won't return it. Returns ErrZeroDurationInterval if the provided duration is less or equal zero.
func (Range) Stratify ¶
Stratify the date range into smaller ranges, with fixed duration and with the given interval between the *starts* of the resulting ranges. In case if the last interval doesn't fit into the given duration, MustStratify won't return it. Returns ErrZeroDurationInterval if the provided duration or interval is less or equal to zero.