Documentation
¶
Index ¶
- Constants
- func Compare(a, b time.Time) int
- func DropDate(t time.Time) time.Time
- func DropTime(t time.Time) time.Time
- func Max(values ...time.Time) time.Time
- func Min(values ...time.Time) time.Time
- func Now() time.Time
- func Parse(value string, layouts ...string) (time.Time, error)
- func ParseInZone(zone *Zone, value string, layouts ...string) (time.Time, error)
- type Clock
- type Dur
- type ManualClock
- type Range
- func (r Range) Has(t time.Time) bool
- func (r Range) Intersect(other Range) (Range, bool)
- func (r Range) IsEmpty() bool
- func (r Range) IsValid() bool
- func (r Range) MarshalJSON() ([]byte, error)
- func (r Range) MarshalText() ([]byte, error)
- func (r Range) Overlaps(other Range) bool
- func (r Range) Span() Span
- func (r Range) String() string
- func (r *Range) UnmarshalJSON(data []byte) error
- func (r *Range) UnmarshalText(data []byte) error
- type Span
- type Spans
- type SystemClock
- type Timestamp
- type UTCClock
- type Zone
Constants ¶
const ( Week = 7 * Day Day = 24 * Hour HalfDay = 12 * Hour Hour = time.Hour Minute = time.Minute Second = time.Second Millisecond = time.Millisecond Microsecond = time.Microsecond Nanosecond = time.Nanosecond )
Variables ¶
This section is empty.
Functions ¶
func DropDate ¶ added in v0.2.0
DropDate replaces the date with January 1, year 0. It preserves the clock components and location.
func DropTime ¶ added in v0.2.0
DropTime replaces the clock components with midnight. It preserves the date and location.
func Max ¶ added in v0.2.0
Max returns the latest nonzero time. It returns the zero time if there are no nonzero values.
func Min ¶ added in v0.2.0
Min returns the earliest nonzero time. It returns the zero time if there are no nonzero values.
Types ¶
type ManualClock ¶
type ManualClock struct {
// contains filtered or unexported fields
}
ManualClock is a clock that can be controlled manually. Its zero value returns the zero time. Methods are safe for concurrent use. A ManualClock must not be copied after first use.
func NewManualClock ¶
func NewManualClock(curr time.Time) *ManualClock
NewManualClock returns a manual clock initialized to curr.
func (*ManualClock) Add ¶
func (c *ManualClock) Add(d time.Duration)
Add advances the clock by the given duration.
func (*ManualClock) Now ¶
func (c *ManualClock) Now() time.Time
Now returns the clock's current time.
func (*ManualClock) Set ¶
func (c *ManualClock) Set(t time.Time)
Set replaces the clock's current time.
type Range ¶ added in v0.2.0
Range represents a half-open interval [Start, Finish). Equal endpoints form a valid empty range. The zero value is a valid empty range.
func ParseRange ¶ added in v0.2.0
func ParseRangeInZone ¶ added in v0.2.0
func (Range) Has ¶ added in v0.2.0
Has reports whether t belongs to [Start, Finish). Invalid and empty ranges contain no instants.
func (Range) Intersect ¶ added in v0.2.0
Intersect returns the non-empty intersection of the ranges. If there is no intersection, it returns Range{} and false.
func (Range) IsEmpty ¶ added in v0.2.0
IsEmpty reports whether the endpoints represent the same instant.
func (Range) MarshalJSON ¶ added in v0.2.0
MarshalJSON encodes the range as a JSON string in UTC.
func (Range) MarshalText ¶ added in v0.2.0
MarshalText encodes the range with both endpoints in UTC.
func (Range) Overlaps ¶ added in v0.2.0
Overlaps reports whether the ranges share a non-empty interval. Adjacent, empty, and invalid ranges do not overlap.
func (Range) Span ¶ added in v0.2.0
Span returns Finish.Sub(Start). Invalid ranges produce a negative duration. Results outside Span's range saturate, following time.Time.Sub.
func (Range) String ¶ added in v0.2.0
String formats the range using its endpoints' local dates and clocks.
The date is omitted when both endpoints have date 0001-01-01. A shared date is printed once; different dates are printed separately. Seconds are included for both endpoints if either has seconds or nanoseconds. Fractional seconds are printed only when non-zero.
Timezone information is omitted. Use endpoints in the same location when an unambiguous local display is required.
func (*Range) UnmarshalJSON ¶ added in v0.2.0
func (*Range) UnmarshalText ¶ added in v0.2.0
type Span ¶ added in v0.2.0
Span represents a duration in nanoseconds. Similar to time.Duration but with improved marshaling.
func (Span) MarshalJSON ¶ added in v0.2.0
func (Span) MarshalText ¶ added in v0.2.0
func (Span) Mul ¶ added in v0.2.0
Mul returns s multiplied by x.
The calculation uses float64 and may lose precision for large durations. Both x and the product must be finite, and the product must be in [-2^63, 2^63). These requirements are not checked.
func (Span) String ¶ added in v0.2.0
String returns the duration formatted like time.Duration.String Omits zero minutes and zero seconds. For example, 1h0m0s becomes 1h, and 1m0s becomes 1m.
func (*Span) UnmarshalJSON ¶ added in v0.2.0
func (*Span) UnmarshalText ¶ added in v0.2.0
type Spans ¶ added in v0.2.0
type Spans []Span
Spans is a slice of Span.
func (Spans) Durs ¶ added in v0.2.0
Durs returns each span as a time.Duration.
type SystemClock ¶ added in v0.2.0
type SystemClock struct{}
SystemClock provides the current local time, including its monotonic reading.
func (SystemClock) Now ¶ added in v0.2.0
func (SystemClock) Now() time.Time
Now returns the current local time.
type Timestamp ¶ added in v0.1.1
func AsTimestamp ¶ added in v0.1.1
AsTimestamp returns time.Time wrapped as Timestamp.
func TimestampFromMilli ¶ added in v0.1.2
TimestampFromMilli returns Timestamp from the Unix time in milliseconds.
func TimestampFromString ¶ added in v0.1.2
TimestampFromString returns Timestamp fomr the string representing Unix time.
func (Timestamp) MarshalJSON ¶ added in v0.1.1
MarshalJSON implements json.Marshaler interface.
func (*Timestamp) UnmarshalJSON ¶ added in v0.1.1
UnmarshalJSON implements json.Unmarshaler interface.