timebox

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: BSD-2-Clause Imports: 2 Imported by: 0

README

GoDoc Go Report Card

Timebox

For documentation please see the GoDoc.

Documentation

Overview

Package timebox implements functions to manage slots. A slot in this package is any tuple of a name, a start time and a duration. Slots can be combined into sets. Sets can be split into non-overlapping sets of slots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set is a container with zero or more slots in it. Slots in a set may overlap each other. You can use the set to calculate lanes from the slots inside.

func NewSet

func NewSet() *Set

NewSet creates a new set.

func (*Set) Add

func (s *Set) Add(slot *Slot)

Add adds a new slot to a set. The slot is passed as a pointer that is stored in the set, so be aware that later changes to the slot affect the set.

func (*Set) All

func (s *Set) All(f func(*Slot) bool) bool

All returns whether any slot in the set satisfies f(slot).

func (*Set) Any

func (s *Set) Any(f func(*Slot) bool) bool

Any returns whether any slot in the set satisfies f(slot).

func (*Set) Contains

func (s *Set) Contains(t time.Time) bool

Contains returns whether any slot in the set contains a given time.

func (*Set) Find

func (s *Set) Find(f func(*Slot) bool) []*Slot

Find returns a slice of all slots in the set satisfying f(slot), or an empty slice if none do. Be aware that any changes to the returned slots affect the set.

func (*Set) Overlaps

func (s *Set) Overlaps(slot *Slot) bool

Overlaps returns whether any slot in the set overlaps a given other slot.

func (*Set) Slots

func (s *Set) Slots() []*Slot

Slots returns a slice of the slots in a set. Be aware that changes to the returned slots affect the set.

func (*Set) SplitLinear

func (s *Set) SplitLinear() []*Set

SplitLinear distributes the slots in the set to multiple sets in a way that ensures that no set contains multiple overlapping slots.

type Slot

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

Slot is a tuple of a name, a start time and a duration.

func NewSlot

func NewSlot(name string, start time.Time, duration time.Duration) *Slot

NewSlot creates a new slot from a name, a start time and a duration.

func NewSlotFromTimes

func NewSlotFromTimes(name string, start, end time.Time) *Slot

NewSlotFromTimes creates a new slot from a name, a start time and an end time. The end time is not contained in the slot.

func (*Slot) Contains

func (s *Slot) Contains(t time.Time) bool

Contains returns whether a time is in a slot. Note that the start time of a slot is contained by it, but not the end time.

func (*Slot) Duration

func (s *Slot) Duration() time.Duration

Duration returns the duration of a slot.

func (*Slot) End

func (s *Slot) End() time.Time

End returns the end time of a slot.

func (*Slot) Name

func (s *Slot) Name() string

Name returns the name given to a slot.

func (*Slot) Overlaps

func (s *Slot) Overlaps(s2 *Slot) bool

Overlaps returns whether two slot overlaps each other, i.e. whether the start time of one slot is contained in the other one. Both directions are tested.

func (*Slot) Start

func (s *Slot) Start() time.Time

Start returns the start time of a slot.

func (*Slot) String

func (s *Slot) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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