timespan

package module
v0.0.0-...-a3d8e47 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2016 License: MIT Imports: 1 Imported by: 2

README

timespan

timespan is a Go library for interacting with intervals of time, defined as a start time and a duration.

Documentation

Installation

Install timespan using the "go get" command:

go get github.com/SaidinWoT/timespan

Contributing

Contributions are welcome. Simply send a pull request my way.

License

timespan is available under the MIT License

Documentation

Overview

Package timespan provides functionality for handling intervals of time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Span

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

Span represents an inclusive range between two time instants.

The zero value of type span has both start and end times set to the zero value of type Time. The zero value is returned by the Intersection and Gap methods when there is no span fitting their purposes.

func New

func New(t time.Time, d time.Duration) Span

New creates a new span with the given start instant and duration.

func (Span) After

func (s Span) After(t time.Time) bool

After reports whether s begins after t.

func (Span) Before

func (s Span) Before(t time.Time) bool

Before reports whether s ends before t.

func (Span) Borders

func (s Span) Borders(r Span) bool

Borders reports whether s and r are contiguous time intervals.

func (Span) Contains

func (s Span) Contains(r Span) bool

Contains reports whether r is entirely within s.

func (Span) ContainsTime

func (s Span) ContainsTime(t time.Time) bool

ContainsTime reports whether t is within s.

func (Span) Duration

func (s Span) Duration() time.Duration

Duration returns the length of time represented by s.

func (Span) Encompass

func (s Span) Encompass(r Span) Span

Encompass returns the minimum span that fully contains both r and s.

func (Span) End

func (s Span) End() time.Time

End returns the time instant at the end of s.

func (Span) Equal

func (s Span) Equal(r Span) bool

Equal reports whether s and r represent the same time intervals, ignoring the locations of the times.

func (Span) Follows

func (s Span) Follows(r Span) bool

Follows reports whether s begins after or at the end of r.

func (Span) Gap

func (s Span) Gap(r Span) Span

Gap returns a span corresponding to the period between s and r. If s and r have a non-zero overlap, a zero span is returned.

func (Span) Intersection

func (s Span) Intersection(r Span) (Span, bool)

Intersection returns both a span corresponding to the non-zero overlap of s and r and a bool indicating whether such an overlap existed. If s and r do not overlap, a zero span is returned with false.

func (Span) IsZero

func (s Span) IsZero() bool

IsZero reports whether s represents the zero-length span starting and ending on January 1, year 1, 00:00:00 UTC.

func (Span) Offset

func (s Span) Offset(d time.Duration) Span

Offset returns s with its start time offset by d. It is equivalent to Newspan(s.Start().Add(d), s.Duration()).

func (Span) OffsetDate

func (s Span) OffsetDate(years, months, days int) Span

OffsetDate returns s with its start time offset by the given years, months, and days. It is equivalent to Newspan(s.Start().AddDate(years, months, days), s.Duration()).

func (Span) Overlaps

func (s Span) Overlaps(r Span) bool

Overlaps reports whether s and r intersect for a non-zero duration.

func (Span) Precedes

func (s Span) Precedes(r Span) bool

Precedes reports whether s ends before or at the start of r.

func (Span) Start

func (s Span) Start() time.Time

Start returns the time instant at the start of s.

Jump to

Keyboard shortcuts

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