Documentation ¶
Index ¶
- func DoesOverlap(a, b Period) bool
- func Duration(period Period) time.Duration
- func Max(a, b Period, timeFunc TimeFunction) time.Time
- func Min(a, b Period, timeFunc TimeFunction) time.Time
- func Overlap(a, b Period) time.Duration
- func Sort(many Periods)
- func Touching(a, b Period) bool
- type Period
- type Periods
- type TimeFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoesOverlap ¶
DoesOverlap returns true if a and b overlap, otherwise false.
a and b are NOT considered to be overlapping if their bounds merely touch - for that see Touching.
func Duration ¶
Duration returns the duration that a period covers. If period is nil,
0 is returned.
func Max ¶
func Max(a, b Period, timeFunc TimeFunction) time.Time
Max returns the maximum time of timeFunc(a) vs. timeFunc(b)
func Min ¶
func Min(a, b Period, timeFunc TimeFunction) time.Time
Min returns the minimum time of timeFunc(a) vs. timeFunc(b)
Types ¶
type Period ¶
type Period interface { Valid() bool Start() time.Time End() time.Time TransformToNew(time.Time, time.Time) Period }
Period is a conventional time period, which is a starting point
in time followed by an ending period of time, plus all the points in-between.
type Periods ¶
type Periods []Period
Periods is a slice of Period. It can itself be considered a Period (and we
implement Period for Periods)... see below.
func CoverGaps ¶
CoverGaps will close any gaps between close elements by stretching those
elements to cover the gap. The degree to which the elements are stretched is determined by their original Duration.
func FixOverlaps ¶
FixOverlaps will adjust any set of overlapping elements in many such that
their bounds touch, and they share the span of their overlapping set in proportion to their original Durations.
func MergeTouching ¶
MergeTouching will merge any touching periods using mergeFunc.
mergeFunc should return a period which has Start = a.Start() and end = b.End(), otherwise the result is not guaranteed to have non-touching elements.
func (Periods) TransformToNew ¶
TransformToNew scales and shifts the elements of Periods, such that
the minimum start of all elements is now "start", and the maximum end of all elements is now "end". The elements are also transformed into new variants, and the relative relationship between elements is unchanged - e.g. if elements 2 and 7 were overlapping, they will continue to overlap by the same percentage after the transformation.
type TimeFunction ¶
TimeFunction must return a time value for a given Period.
Generally, this will be Period.Start or Period.End.