interval

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package interval provides half-open time interval algebra: the foundation for merging free/busy data across many calendars.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set []Span

Set is a normalized sequence of spans: sorted by start, non-empty, non-overlapping, non-adjacent. Construct with Normalize or the Set methods; all methods preserve the invariant.

func Normalize

func Normalize(spans []Span) Set

Normalize sorts spans, drops empty ones, and merges overlapping or adjacent ones.

func (Set) Complement

func (s Set) Complement(window Span) Set

Complement returns the gaps of s within the window.

func (Set) ContainsSpan

func (s Set) ContainsSpan(t Span) bool

ContainsSpan reports whether t lies entirely within a single span of s.

func (Set) Intersect

func (s Set) Intersect(t Set) Set

Intersect returns all time covered by both s and t.

func (Set) Shrink

func (s Set) Shrink(before, after time.Duration) Set

Shrink trims each span by before on the left and after on the right, dropping spans that become empty. The inverse of padding: shrinking a free set by travel time yields the times at which a padded event still fits.

func (Set) Subtract

func (s Set) Subtract(t Set) Set

Subtract returns the time covered by s but not by t.

func (Set) Union

func (s Set) Union(t Set) Set

Union returns all time covered by s or t.

type Span

type Span struct {
	Start time.Time
	End   time.Time
}

Span is a half-open interval [Start, End). A Span with End <= Start is considered empty.

func (Span) Contains

func (s Span) Contains(t Span) bool

Contains reports whether t lies entirely within s.

func (Span) Duration

func (s Span) Duration() time.Duration

Duration returns the length of the span (zero for empty spans).

func (Span) IsEmpty

func (s Span) IsEmpty() bool

IsEmpty reports whether the span covers no time.

func (Span) Overlaps

func (s Span) Overlaps(t Span) bool

Overlaps reports whether s and t share any instant.

func (Span) Pad

func (s Span) Pad(before, after time.Duration) Span

Pad expands the span by before on the left and after on the right.

Jump to

Keyboard shortcuts

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