Source File
time.go
Belonging Package
github.com/quic-go/quic-go/internal/monotime
// Package monotime provides a monotonic time representation that is useful for// measuring elapsed time.// It is designed as a memory optimized drop-in replacement for time.Time, with// a monotime.Time consuming just 8 bytes instead of 24 bytes.package monotimeimport ()// The absolute value doesn't matter, but it should be in the past,// so that every timestamp obtained with Now() is non-zero,// even on systems with low timer resolutions (e.g. Windows).var start = time.Now().Add(-time.Hour)// A Time represents an instant in monotonic time.// Times can be compared using the comparison operators, but the specific// value is implementation-dependent and should not be relied upon.// The zero value of Time doesn't have any specific meaning.type Time int64// Now returns the current monotonic time.func () Time {return Time(time.Since(start).Nanoseconds())}// Sub returns the duration t-t2. If the result exceeds the maximum (or minimum)// value that can be stored in a Duration, the maximum (or minimum) duration// will be returned.// To compute t-d for a duration d, use t.Add(-d).func ( Time) ( Time) time.Duration {return time.Duration( - )}// Add returns the time t+d.func ( Time) ( time.Duration) Time {return Time(int64() + .Nanoseconds())}// After reports whether the time instant t is after t2.func ( Time) ( Time) bool {return >}// Before reports whether the time instant t is before t2.func ( Time) ( Time) bool {return <}// IsZero reports whether t represents the zero time instant.func ( Time) () bool {return == 0}// Equal reports whether t and t2 represent the same time instant.func ( Time) ( Time) bool {return ==}// ToTime converts the monotonic time to a time.Time value.// The returned time.Time will have the same instant as the monotonic time,// but may be subject to clock adjustments.func ( Time) () time.Time {if .IsZero() {return time.Time{}}return start.Add(time.Duration())}// Since returns the time elapsed since t. It is shorthand for Now().Sub(t).func ( Time) time.Duration {return Now().Sub()}// Until returns the duration until t.// It is shorthand for t.Sub(Now()).// If t is in the past, the returned duration will be negative.func ( Time) time.Duration {return time.Duration( - Now())}// FromTime converts a time.Time to a monotonic Time.// The conversion is relative to the package's start time and may lose// precision if the time.Time is far from the start time.func ( time.Time) Time {if .IsZero() {return 0}return Time(.Sub(start).Nanoseconds())}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |