Documentation ¶
Overview ¶
Package time defines newtypes around zx.Time and zx.Duration that provide a subset of the std time.Time and time.Duration API.
The std time package unfortunately [blurs the distinction](https://pkg.go.dev/time#hdr-Monotonic_Clocks) between wallclock and monotonic times. Operations from std time provide no type safety to preserve monotonicity in time values. Indeed, some std time methods and functions will silently erase the monotonic component of the value. This package defines its newtypes as monotonic time values and as such are intended for use in setting deadlines and expirations in Fuchsia netstack.
Users of this package should use it in place of the std time package. Given the blurred semantics of std time, using this package alongside std time is potentially hazardous and should only be done with care.
Index ¶
Constants ¶
const ( Nanosecond Duration = 1 Microsecond = 1000 * Nanosecond Millisecond = 1000 * Microsecond Second = 1000 * Millisecond Minute = 60 * Second Hour = 60 * Minute )
Variables ¶
This section is empty.
Functions ¶
func After ¶
After waits for duration to elapse and then sends the current monotonic time on the returned channel.
func ContextWithTimeout ¶
ContextWithTimeout returns a copy of the parent context with its timeout set to the value of the supplied duration. This function allows current users of Duration to avoid a direct dependency on the std time package which has different semantics and should not be freely used with the types in this package.
Types ¶
type Duration ¶
A Duration represents the nanosecond count between two Time instants.
func (Duration) Microseconds ¶
Microseconds returns the duration as an integer microsecond count.
func (Duration) Milliseconds ¶
Milliseconds returns the duration as an integer millisecond count.
func (Duration) Nanoseconds ¶
Nanoseconds returns the duration as an integer nanosecond count.
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
A Time represents a monotonic instant in time since system start with nanosecond precision.
func Monotonic ¶
Monotonic returns the monotonic time corresponding to the given nanosecond count. It is the analogue of std time.Unix() but without any reference to the Unix epoch.
func (Time) Add ¶
Add returns the Time t+d. If the sum is such as to exceed the maximum or minimum Time value, the maximum or minimum will be returned, respectively.
func (Time) MonotonicNano ¶
MonotonicNano returns the time as a nanosecond count. It is the analogue of std time.Time.UnixNano() but without any reference to the Unix epoch.
func (Time) String ¶
String returns the time formatted using the format string:
"m=+-<value>"
where m indicates the monotonic component of the value. This format is the analogue of the std time.Time.String() format, with the non-monotonic components of the string removed. String presents its value in decimal units of seconds. String is intended solely for debugging.