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 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 Since(t UnixNano) time.Duration
- 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
- func UnitCount() int
- 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 UnixNano) (shouldContinue bool))
- func (r Range) IterateForward(stepSize time.Duration, f func(t UnixNano) (shouldContinue bool))
- func (r Range) Merge(other Range) Range
- func (r Range) Overlaps(other Range) bool
- func (r Range) Since(t UnixNano) Range
- func (r Range) String() string
- func (r Range) Subtract(other Range) []Range
- type RangeIter
- type Ranges
- type Unit
- type UnixNano
- func FromNormalizedTime(nt int64, u time.Duration) UnixNano
- func FromSeconds(seconds int64) UnixNano
- func FromSecondsAndNanos(seconds int64, nanos int64) UnixNano
- func MaxUnixNano(t1, t2 UnixNano) UnixNano
- func MinUnixNano(t1, t2 UnixNano) UnixNano
- func Now() UnixNano
- func ToUnixNano(t time.Time) UnixNano
- func (u UnixNano) Add(d time.Duration) UnixNano
- func (u UnixNano) After(t UnixNano) bool
- func (u UnixNano) Before(t UnixNano) bool
- func (u UnixNano) Equal(t UnixNano) bool
- func (u UnixNano) Format(blockTimeFormat string) string
- func (u UnixNano) FromNormalizedTime(d time.Duration) UnixNano
- func (u UnixNano) IsZero() bool
- func (u UnixNano) Seconds() int64
- func (u UnixNano) String() string
- func (u UnixNano) Sub(o UnixNano) time.Duration
- func (u UnixNano) ToNormalizedTime(d time.Duration) int64
- func (u UnixNano) ToTime() time.Time
- func (u UnixNano) Truncate(d time.Duration) 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 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 Since ¶ added in v1.4.0
Since returns the time elapsed since t. It is shorthand for time.Now().Sub(t).
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 ¶ added in v0.11.0
IterateBackward iterates through a time range by step size in the backwards direction.
func (Range) IterateForward ¶ added in v0.11.0
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 interface { AddRange(Range) AddRanges(Ranges) RemoveRange(Range) RemoveRanges(Ranges) Overlaps(Range) bool Iter() *RangeIter Clone() Ranges Len() int IsEmpty() bool String() string }
Ranges is a collection of time ranges.
type Unit ¶
type Unit uint16
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 FromNormalizedTime ¶
FromNormalizedTime returns the time given the normalized time units and the time unit.
func FromSeconds ¶ added in v1.2.0
FromSeconds returns the UnixNano representation of the local Time corresponding to the seconds since January 1, 1970 UTC.
func FromSecondsAndNanos ¶ added in v1.2.0
FromSecondsAndNanos returns the UnixNano representation of the local Time corresponding to the seconds and nanoseconds since January 1, 1970 UTC.
func MaxUnixNano ¶ added in v1.2.0
MaxUnixNano returns the later one of t1 and t2.
func MinUnixNano ¶ added in v1.2.0
MinUnixNano returns the earlier one of t1 and t2.
func Now ¶ added in v1.2.0
func Now() UnixNano
Now returns the current local time, in nanoseconds elapsed since January 1, 1970 UTC. NB: This is independent of location.
func ToUnixNano ¶
ToUnixNano returns a UnixNano from a time.Time.
func (UnixNano) Format ¶ added in v1.2.0
Format returns the string representation for the time with the given format.
func (UnixNano) FromNormalizedTime ¶ added in v1.2.0
FromNormalizedTime returns the time given the normalized time units and the time unit.
func (UnixNano) String ¶ added in v1.2.0
String returns the time formatted using the format string
"2006-01-02 15:04:05.999999999 -0700 MST"
func (UnixNano) Sub ¶ added in v1.2.0
Sub returns the duration u-o. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned.
func (UnixNano) ToNormalizedTime ¶ added in v1.2.0
ToNormalizedTime returns the normalized units of time given a time unit.