Documentation ¶
Overview ¶
Package time implement facilities for working with time.
Index ¶
- func Ceil(t time.Time, d time.Duration) time.Time
- func DurationFromUnit(u Unit) (time.Duration, error)
- func FromNanoseconds(nsecs int64) time.Time
- func FromNormalizedDuration(nd int64, u time.Duration) time.Duration
- func FromNormalizedTime(nt int64, u time.Duration) time.Time
- func FromUnixMillis(ms int64) time.Time
- func MaxTime(t1, t2 time.Time) time.Time
- func MinTime(t1, t2 time.Time) time.Time
- func ParseExtendedDuration(s string) (time.Duration, error)
- func ToExtendedString(d time.Duration) string
- func ToNanoseconds(t time.Time) int64
- func ToNormalizedDuration(d time.Duration, u time.Duration) int64
- func ToNormalizedTime(t time.Time, u time.Duration) int64
- func ToUnixMillis(t time.Time) int64
- type Matcher
- type Range
- func (r Range) After(other Range) bool
- func (r Range) Before(other Range) bool
- func (r Range) Contains(other Range) bool
- func (r Range) Duration() time.Duration
- func (r Range) Equal(other Range) bool
- func (r Range) Intersect(other Range) (Range, bool)
- func (r Range) IsEmpty() bool
- func (r Range) IterateBackward(stepSize time.Duration, f func(t time.Time) (shouldContinue bool))
- func (r Range) IterateForward(stepSize time.Duration, f func(t time.Time) (shouldContinue bool))
- func (r Range) Merge(other Range) Range
- func (r Range) Overlaps(other Range) bool
- func (r Range) Since(t time.Time) Range
- func (r Range) String() string
- func (r Range) Subtract(other Range) []Range
- type RangeIter
- type Ranges
- func (tr Ranges) AddRange(r Range) Ranges
- func (tr Ranges) AddRanges(other Ranges) Ranges
- func (tr Ranges) IsEmpty() bool
- func (tr Ranges) Iter() *RangeIter
- func (tr Ranges) Len() int
- func (tr Ranges) Overlaps(r Range) bool
- func (tr Ranges) RemoveRange(r Range) Ranges
- func (tr Ranges) RemoveRanges(other Ranges) Ranges
- func (tr Ranges) String() string
- type Unit
- type UnixNano
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DurationFromUnit ¶
DurationFromUnit creates a time duration from a time unit.
func FromNanoseconds ¶
FromNanoseconds converts nanoseconds to a time.
func FromNormalizedDuration ¶
FromNormalizedDuration returns the duration given the normalized time duration and a time unit.
func FromNormalizedTime ¶
FromNormalizedTime returns the time given the normalized time units and the time unit.
func FromUnixMillis ¶
FromUnixMillis converts milliseconds since Unix epoch to a time
func ParseExtendedDuration ¶
ParseExtendedDuration parses a duration, with the ability to specify time units in days, weeks, months, and years.
func ToExtendedString ¶
ToExtendedString converts a duration to an extended string.
func ToNanoseconds ¶
ToNanoseconds converts a time to nanoseconds.
func ToNormalizedDuration ¶
ToNormalizedDuration returns the normalized units of duration given a time unit.
func ToNormalizedTime ¶
ToNormalizedTime returns the normalized units of time given a time unit.
func ToUnixMillis ¶
ToUnixMillis converts a time to milliseconds since Unix epoch
Types ¶
type Range ¶
Range represents [start, end)
func (Range) Intersect ¶
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) IterateBackward ¶
IterateBackward iterates through a time range by step size in the backwards direction.
func (Range) IterateForward ¶
IterateForward iterates through a time range by step size in the forwards direction.
func (Range) Merge ¶
Merge merges the two ranges if they overlap. Otherwise, the gap between them is included.
type RangeIter ¶
type RangeIter struct {
// contains filtered or unexported fields
}
RangeIter iterates over a collection of time ranges.
type Ranges ¶
type Ranges struct {
// contains filtered or unexported fields
}
Ranges is a collection of time ranges.
func (Ranges) Overlaps ¶
Overlaps checks if the range overlaps with any of the ranges in the collection.
func (Ranges) RemoveRange ¶
RemoveRange removes the time range from the collection of ranges.
func (Ranges) RemoveRanges ¶
RemoveRanges removes the given time ranges from the current one.
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 ¶
MaxUnitForDuration determines the maximum unit for which the input duration is a multiple of.
func UnitFromDuration ¶
UnitFromDuration creates a time unit from a time duration.
func (Unit) MustCount ¶
MustCount is like Count but panics if d is negative or if tu is not a valid Unit.
type UnixNano ¶
type UnixNano int64
UnixNano is used to indicate that an int64 stores a unix timestamp at nanosecond resolution
func ToUnixNano ¶
ToUnixNano returns a UnixNano from a time.Time