time

package
v0.0.0-...-9649366 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package time implement facilities for working with time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ceil

func Ceil(t time.Time, d time.Duration) time.Time

Ceil returns the result of rounding t up to a multiple of d since the zero time.

func DurationFromUnit

func DurationFromUnit(u Unit) (time.Duration, error)

DurationFromUnit creates a time duration from a time unit.

func FromNanoseconds

func FromNanoseconds(nsecs int64) time.Time

FromNanoseconds converts nanoseconds to a time.

func FromNormalizedDuration

func FromNormalizedDuration(nd int64, u time.Duration) time.Duration

FromNormalizedDuration returns the duration given the normalized time duration and a time unit.

func FromNormalizedTime

func FromNormalizedTime(nt int64, u time.Duration) time.Time

FromNormalizedTime returns the time given the normalized time units and the time unit.

func FromUnixMillis

func FromUnixMillis(ms int64) time.Time

FromUnixMillis converts milliseconds since Unix epoch to a time

func MaxTime

func MaxTime(t1, t2 time.Time) time.Time

MaxTime returns the later one of t1 and t2.

func MinTime

func MinTime(t1, t2 time.Time) time.Time

MinTime returns the earlier one of t1 and t2.

func ParseExtendedDuration

func ParseExtendedDuration(s string) (time.Duration, error)

ParseExtendedDuration parses a duration, with the ability to specify time units in days, weeks, months, and years.

func ToExtendedString

func ToExtendedString(d time.Duration) string

ToExtendedString converts a duration to an extended string.

func ToNanoseconds

func ToNanoseconds(t time.Time) int64

ToNanoseconds converts a time to nanoseconds.

func ToNormalizedDuration

func ToNormalizedDuration(d time.Duration, u time.Duration) int64

ToNormalizedDuration returns the normalized units of duration given a time unit.

func ToNormalizedTime

func ToNormalizedTime(t time.Time, u time.Duration) int64

ToNormalizedTime returns the normalized units of time given a time unit.

func ToUnixMillis

func ToUnixMillis(t time.Time) int64

ToUnixMillis converts a time to milliseconds since Unix epoch

Types

type Matcher

type Matcher interface {
	gomock.Matcher
}

Matcher is a gomock.Matcher that matches time.Time

func NewMatcher

func NewMatcher(t time.Time) Matcher

NewMatcher returns a new Matcher

type Range

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

Range represents [start, end)

func (Range) After

func (r Range) After(other Range) bool

After determines whether r is after other.

func (Range) Before

func (r Range) Before(other Range) bool

Before determines whether r is before other.

func (Range) Contains

func (r Range) Contains(other Range) bool

Contains determines whether r contains other.

func (Range) Duration

func (r Range) Duration() time.Duration

Duration returns the duration of the range.

func (Range) Equal

func (r Range) Equal(other Range) bool

Equal returns whether two time ranges are equal.

func (Range) Intersect

func (r Range) Intersect(other Range) (Range, bool)

Intersect calculates the intersection of the receiver range against the provided argument range iff there is an overlap between the two. It also returns a bool indicating if there was a valid intersection.

func (Range) IsEmpty

func (r Range) IsEmpty() bool

IsEmpty returns whether the time range is empty.

func (Range) IterateBackward

func (r Range) IterateBackward(stepSize time.Duration, f func(t time.Time) (shouldContinue bool))

IterateBackward iterates through a time range by step size in the backwards direction.

func (Range) IterateForward

func (r Range) IterateForward(stepSize time.Duration, f func(t time.Time) (shouldContinue bool))

IterateForward iterates through a time range by step size in the forwards direction.

func (Range) Merge

func (r Range) Merge(other Range) Range

Merge merges the two ranges if they overlap. Otherwise, the gap between them is included.

func (Range) Overlaps

func (r Range) Overlaps(other Range) bool

Overlaps determines whether r overlaps with other.

func (Range) Since

func (r Range) Since(t time.Time) Range

Since returns the time range since a given point in time.

func (Range) String

func (r Range) String() string

String returns the string representation of the range.

func (Range) Subtract

func (r Range) Subtract(other Range) []Range

Subtract removes the intersection between r and other from r, possibly splitting r into two smaller ranges.

type RangeIter

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

RangeIter iterates over a collection of time ranges.

func (*RangeIter) Next

func (it *RangeIter) Next() bool

Next moves to the next item.

func (*RangeIter) Value

func (it *RangeIter) Value() Range

Value returns the current time range.

type Ranges

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

Ranges is a collection of time ranges.

func NewRanges

func NewRanges(ranges ...Range) Ranges

NewRanges constructs a new Ranges object comprising the provided ranges.

func (Ranges) AddRange

func (tr Ranges) AddRange(r Range) Ranges

AddRange adds the time range to the collection of ranges.

func (Ranges) AddRanges

func (tr Ranges) AddRanges(other Ranges) Ranges

AddRanges adds the time ranges.

func (Ranges) IsEmpty

func (tr Ranges) IsEmpty() bool

IsEmpty returns true if the list of time ranges is empty.

func (Ranges) Iter

func (tr Ranges) Iter() *RangeIter

Iter returns an iterator that iterates over the time ranges included.

func (Ranges) Len

func (tr Ranges) Len() int

Len returns the number of ranges included.

func (Ranges) Overlaps

func (tr Ranges) Overlaps(r Range) bool

Overlaps checks if the range overlaps with any of the ranges in the collection.

func (Ranges) RemoveRange

func (tr Ranges) RemoveRange(r Range) Ranges

RemoveRange removes the time range from the collection of ranges.

func (Ranges) RemoveRanges

func (tr Ranges) RemoveRanges(other Ranges) Ranges

RemoveRanges removes the given time ranges from the current one.

func (Ranges) String

func (tr Ranges) String() string

String returns the string representation of the range.

type Unit

type Unit byte

Unit represents a time unit.

const (
	// None is a place holder for time units, it doesn't represent an actual time unit. The ordering
	// here is used for comparisons betweens units and should not be changed.
	None Unit = iota
	Second
	Millisecond
	Microsecond
	Nanosecond
	Minute
	Hour
	Day
	Year
)

Different time units that are supported.

func MaxUnitForDuration

func MaxUnitForDuration(d time.Duration) (int64, Unit)

MaxUnitForDuration determines the maximum unit for which the input duration is a multiple of.

func UnitFromDuration

func UnitFromDuration(d time.Duration) (Unit, error)

UnitFromDuration creates a time unit from a time duration.

func (Unit) Count

func (tu Unit) Count(d time.Duration) (int, error)

Count returns the number of units contained within the duration.

func (Unit) IsValid

func (tu Unit) IsValid() bool

IsValid returns whether the given time unit is valid / supported.

func (Unit) MustCount

func (tu Unit) MustCount(d time.Duration) int

MustCount is like Count but panics if d is negative or if tu is not a valid Unit.

func (Unit) String

func (tu Unit) String() string

String returns the string representation for the time unit

func (Unit) Value

func (tu Unit) Value() (time.Duration, error)

Value is the time duration of the time unit.

type UnixNano

type UnixNano int64

UnixNano is used to indicate that an int64 stores a unix timestamp at nanosecond resolution

func ToUnixNano

func ToUnixNano(t time.Time) UnixNano

ToUnixNano returns a UnixNano from a time.Time

func (UnixNano) After

func (u UnixNano) After(t UnixNano) bool

After reports whether the time instant u is after t.

func (UnixNano) Before

func (u UnixNano) Before(t UnixNano) bool

Before reports whether the time instant u is before t.

func (UnixNano) Equal

func (u UnixNano) Equal(t UnixNano) bool

Equal reports whether the time instant u is equal to t.

func (UnixNano) ToTime

func (u UnixNano) ToTime() time.Time

ToTime returns a time.ToTime from a UnixNano

Jump to

Keyboard shortcuts

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