Documentation
¶
Index ¶
- Constants
- func AsTimed[T any](fn func(T) time.Time) func(T) Timed[T]
- func Compare(a, b time.Time) int
- type ClosedPeriod
- func (p ClosedPeriod) Contains(t time.Time) bool
- func (p ClosedPeriod) ContainsExclusive(t time.Time) bool
- func (p ClosedPeriod) ContainsInclusive(t time.Time) bool
- func (p ClosedPeriod) Duration() time.Duration
- func (p ClosedPeriod) Intersection(other ClosedPeriod) *ClosedPeriod
- func (p ClosedPeriod) Open() OpenPeriod
- func (p ClosedPeriod) Overlaps(other ClosedPeriod) bool
- func (p ClosedPeriod) OverlapsInclusive(other ClosedPeriod) bool
- type OpenPeriod
- func (p OpenPeriod) Closed() (ClosedPeriod, error)
- func (p OpenPeriod) Contains(t time.Time) bool
- func (p OpenPeriod) ContainsExclusive(t time.Time) bool
- func (p OpenPeriod) ContainsInclusive(t time.Time) bool
- func (p OpenPeriod) Difference(other OpenPeriod) []OpenPeriod
- func (p OpenPeriod) Equals(other OpenPeriod) bool
- func (p OpenPeriod) Intersection(other OpenPeriod) *OpenPeriod
- func (p OpenPeriod) IsSupersetOf(other OpenPeriod) bool
- func (p OpenPeriod) Union(other OpenPeriod) OpenPeriod
- type Period
- type Recurrence
- func (r Recurrence) GetPeriodAt(t time.Time) (ClosedPeriod, error)
- func (r Recurrence) Next(t time.Time) (time.Time, error)
- func (r Recurrence) NextAfter(t time.Time) (time.Time, error)
- func (r Recurrence) Prev(t time.Time) (time.Time, error)
- func (r Recurrence) PrevBefore(t time.Time) (time.Time, error)
- func (r Recurrence) Validate() error
- type RecurrenceInterval
- type SimpleTimeline
- type Timed
- type Timeline
- func (t Timeline[T]) After(at time.Time) Timeline[T]
- func (t Timeline[T]) Before(at time.Time) Timeline[T]
- func (t Timeline[T]) GetAt(idx int) Timed[T]
- func (t Timeline[T]) GetBoundingPeriod() ClosedPeriod
- func (t Timeline[T]) GetClosedPeriods() []ClosedPeriod
- func (t Timeline[T]) GetOpenPeriods() []OpenPeriod
- func (t Timeline[T]) GetTimes() []time.Time
Constants ¶
const MAX_SAFE_ITERATIONS = 10000
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClosedPeriod ¶
func (ClosedPeriod) Contains ¶
func (p ClosedPeriod) Contains(t time.Time) bool
Inclusive at start, exclusive at end
func (ClosedPeriod) ContainsExclusive ¶
func (p ClosedPeriod) ContainsExclusive(t time.Time) bool
Exclusive at both start and end
func (ClosedPeriod) ContainsInclusive ¶
func (p ClosedPeriod) ContainsInclusive(t time.Time) bool
Inclusive at both start and end
func (ClosedPeriod) Duration ¶
func (p ClosedPeriod) Duration() time.Duration
func (ClosedPeriod) Intersection ¶
func (p ClosedPeriod) Intersection(other ClosedPeriod) *ClosedPeriod
func (ClosedPeriod) Open ¶
func (p ClosedPeriod) Open() OpenPeriod
func (ClosedPeriod) Overlaps ¶
func (p ClosedPeriod) Overlaps(other ClosedPeriod) bool
Returns true if the two periods overlap at any point Returns false if the periods are exactly sequential, e.g.: [1, 2] and [2, 3]
func (ClosedPeriod) OverlapsInclusive ¶
func (p ClosedPeriod) OverlapsInclusive(other ClosedPeriod) bool
Returns true if the two periods overlap at any point Returns true if the periods are exactly sequential, e.g.: [1, 2] and [2, 3]
type OpenPeriod ¶
type OpenPeriod struct {
From *time.Time `json:"from,omitempty"`
To *time.Time `json:"to,omitempty"`
}
func (OpenPeriod) Closed ¶
func (p OpenPeriod) Closed() (ClosedPeriod, error)
func (OpenPeriod) Contains ¶
func (p OpenPeriod) Contains(t time.Time) bool
Inclusive at start, exclusive at end
func (OpenPeriod) ContainsExclusive ¶
func (p OpenPeriod) ContainsExclusive(t time.Time) bool
Exclusive at both start and end
func (OpenPeriod) ContainsInclusive ¶
func (p OpenPeriod) ContainsInclusive(t time.Time) bool
Inclusive at both start and end
func (OpenPeriod) Difference ¶
func (p OpenPeriod) Difference(other OpenPeriod) []OpenPeriod
Difference returns P - Other (times in P not in Other)
func (OpenPeriod) Equals ¶
func (p OpenPeriod) Equals(other OpenPeriod) bool
func (OpenPeriod) Intersection ¶
func (p OpenPeriod) Intersection(other OpenPeriod) *OpenPeriod
func (OpenPeriod) IsSupersetOf ¶
func (p OpenPeriod) IsSupersetOf(other OpenPeriod) bool
IsSupersetOf returns true if p contains other (both ends inclusive)
func (OpenPeriod) Union ¶
func (p OpenPeriod) Union(other OpenPeriod) OpenPeriod
type Recurrence ¶
type Recurrence struct {
Interval RecurrenceInterval `json:"period"`
// Anchor can be an arbitrary anchor time for the recurrence.
// It does not have to be the last or the next time.
Anchor time.Time `json:"anchor"`
}
func (Recurrence) GetPeriodAt ¶
func (r Recurrence) GetPeriodAt(t time.Time) (ClosedPeriod, error)
Returns a period where p.Contains(t) is true
func (Recurrence) NextAfter ¶
NextAfter returns the next time after t that the recurrence should occur. If at t the recurrence should occur, it will return t.
func (Recurrence) PrevBefore ¶
PrevBefore returns the previous time before t that the recurrence should occur.
func (Recurrence) Validate ¶
func (r Recurrence) Validate() error
type RecurrenceInterval ¶
var ( RecurrencePeriodDaily RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(0, 0, 0, 1, 0, 0, 0)} RecurrencePeriodWeek RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(0, 0, 1, 0, 0, 0, 0)} RecurrencePeriodMonth RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(0, 1, 0, 0, 0, 0, 0)} RecurrencePeriodYear RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(1, 0, 0, 0, 0, 0, 0)} )
type SimpleTimeline ¶
func NewSimpleTimeline ¶
func NewSimpleTimeline(times []time.Time) SimpleTimeline
type Timeline ¶
type Timeline[T any] struct { // contains filtered or unexported fields }
func NewTimeline ¶
func (Timeline[T]) GetBoundingPeriod ¶
func (t Timeline[T]) GetBoundingPeriod() ClosedPeriod
func (Timeline[T]) GetClosedPeriods ¶
func (t Timeline[T]) GetClosedPeriods() []ClosedPeriod
GetClosedPeriods returns the closed periods between the times in the timeline.
func (Timeline[T]) GetOpenPeriods ¶
func (t Timeline[T]) GetOpenPeriods() []OpenPeriod
GetOpenPeriods returns the open periods between the times in the timeline. For non-empty timelines, the first and last periods will be open at the start and end of the timeline respectively while the rest will effectively be closed.