Documentation
¶
Overview ¶
Package realtime provides a thin wrapper around the time package. It works with time.Time and time.Duration values. Timer and Ticker override their corresponding C fields with a method, to work around the limitation of interfaces not being able to specify fields.
Index ¶
- Constants
- Variables
- type Clock
- func (Clock) After(d Duration) <-chan Time
- func (Clock) AfterFunc(d Duration, f func()) *Timer
- func (Clock) Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time
- func (Clock) FixedZone(name string, offset int) *Location
- func (Clock) Hours(n float64) Duration
- func (Clock) LoadLocation(name string) (*Location, error)
- func (Clock) LoadLocationFromTZData(name string, data []byte) (*Location, error)
- func (Clock) Microseconds(n int64) Duration
- func (Clock) Milliseconds(n int64) Duration
- func (Clock) Minutes(n float64) Duration
- func (Clock) Nanoseconds(n int64) Duration
- func (Clock) NewTicker(d Duration) *Ticker
- func (Clock) NewTimer(d Duration) *Timer
- func (Clock) Now() Time
- func (Clock) Parse(layout, value string) (Time, error)
- func (Clock) ParseDuration(s string) (Duration, error)
- func (Clock) ParseInLocation(layout, value string, loc *Location) (Time, error)
- func (Clock) Seconds(n float64) Duration
- func (Clock) Since(t Time) Duration
- func (Clock) Sleep(d Duration)
- func (Clock) Tick(d Duration) <-chan Time
- func (Clock) Unix(sec int64, nsec int64) Time
- func (Clock) UnixMicro(usec int64) Time
- func (Clock) UnixMilli(msec int64) Time
- func (Clock) UnixNano(nsec int64) Time
- func (Clock) Until(t Time) Duration
- type Duration
- type Location
- type Month
- type ParseError
- type Ticker
- type Time
- type Timer
- type Weekday
Constants ¶
const ( Nanosecond = time.Nanosecond Microsecond = time.Microsecond Millisecond = time.Millisecond Second = time.Second Minute = time.Minute Hour = time.Hour )
Duration constants.
const ( January = time.January February = time.February March = time.March April = time.April May = time.May June = time.June July = time.July August = time.August September = time.September October = time.October November = time.November December = time.December )
Month constants.
const ( Sunday = time.Sunday Monday = time.Monday Tuesday = time.Tuesday Wednesday = time.Wednesday Thursday = time.Thursday Friday = time.Friday Saturday = time.Saturday )
Weekday constants.
const ( Layout = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order. ANSIC = "Mon Jan _2 15:04:05 2006" UnixDate = "Mon Jan _2 15:04:05 MST 2006" RubyDate = "Mon Jan 02 15:04:05 -0700 2006" RFC822 = "02 Jan 06 15:04 MST" RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone RFC850 = "Monday, 02-Jan-06 15:04:05 MST" RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST" RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone RFC3339 = "2006-01-02T15:04:05Z07:00" RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" Kitchen = "3:04PM" // Handy time stamps. Stamp = "Jan _2 15:04:05" StampMilli = "Jan _2 15:04:05.000" StampMicro = "Jan _2 15:04:05.000000" StampNano = "Jan _2 15:04:05.000000000" DateTime = "2006-01-02 15:04:05" DateOnly = "2006-01-02" TimeOnly = "15:04:05" )
Layouts (See time.Layout).
Variables ¶
var Local = time.Local
See time.Local.
var UTC = time.UTC
See time.UTC.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct{}
Clock wraps package-level functions from time. Its methods are thread-safe and Clock objects may be copied freely. The zero-value of a Clock is perfectly valid.
func (Clock) After ¶
After waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to clock.NewTimer(d).C(). The underlying Timer is not recovered by the garbage collector until the timer fires. If efficiency is a concern, use clock.NewTimer instead and call Timer.Stop if the timer is no longer needed.
func (Clock) AfterFunc ¶
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
func (Clock) FixedZone ¶
See time.FixedZone.
func (Clock) LoadLocation ¶
See time.LoadLocation.
func (Clock) LoadLocationFromTZData ¶
func (Clock) Microseconds ¶
Microseconds returns a Duration value representing n microseconds.
func (Clock) Milliseconds ¶
Milliseconds returns a Duration value representing n milliseconds.
func (Clock) Nanoseconds ¶
Nanoseconds returns a Duration value representing n nanoseconds.
func (Clock) NewTicker ¶
NewTicker returns a new Ticker containing a channel that will send the current time on the channel after each tick. The period of the ticks is specified by the duration argument. The ticker will adjust the time interval or drop ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. Stop the ticker to release associated resources.
func (Clock) NewTimer ¶
NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
func (Clock) ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
func (Clock) ParseInLocation ¶
See time.ParseInLocation.
func (Clock) Since ¶
Since returns the time elapsed since t. It is shorthand for clock.Now().Sub(t).
func (Clock) Sleep ¶
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func (Clock) Tick ¶
Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.
type Ticker ¶
Ticker wraps time.Ticker to provide an interfaceable implementation.
type Timer ¶
Timer wraps time.Timer to provide an interfaceable implementation.