realtime

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 1 Imported by: 0

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

View Source
const (
	Nanosecond  = time.Nanosecond
	Microsecond = time.Microsecond
	Millisecond = time.Millisecond
	Second      = time.Second
	Minute      = time.Minute
	Hour        = time.Hour
)

Duration constants.

View Source
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.

View Source
const (
	Sunday    = time.Sunday
	Monday    = time.Monday
	Tuesday   = time.Tuesday
	Wednesday = time.Wednesday
	Thursday  = time.Thursday
	Friday    = time.Friday
	Saturday  = time.Saturday
)

Weekday constants.

View Source
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

View Source
var Local = time.Local

See time.Local.

View Source
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 NewClock

func NewClock() Clock

NewClock returns a new Clock.

func (Clock) After

func (Clock) After(d Duration) <-chan Time

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

func (Clock) AfterFunc(d Duration, f func()) *Timer

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) Date

func (Clock) Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time

See time.Date.

func (Clock) FixedZone

func (Clock) FixedZone(name string, offset int) *Location

See time.FixedZone.

func (Clock) Hours

func (Clock) Hours(n float64) Duration

Hours returns a Duration value representing n Hours.

func (Clock) LoadLocation

func (Clock) LoadLocation(name string) (*Location, error)

See time.LoadLocation.

func (Clock) LoadLocationFromTZData

func (Clock) LoadLocationFromTZData(name string, data []byte) (*Location, error)

See time.LoadLocationFromTZData.

func (Clock) Microseconds

func (Clock) Microseconds(n int64) Duration

Microseconds returns a Duration value representing n microseconds.

func (Clock) Milliseconds

func (Clock) Milliseconds(n int64) Duration

Milliseconds returns a Duration value representing n milliseconds.

func (Clock) Minutes

func (Clock) Minutes(n float64) Duration

Minutes returns a Duration value representing n Minutes.

func (Clock) Nanoseconds

func (Clock) Nanoseconds(n int64) Duration

Nanoseconds returns a Duration value representing n nanoseconds.

func (Clock) NewTicker

func (Clock) NewTicker(d Duration) *Ticker

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

func (Clock) NewTimer(d Duration) *Timer

NewTimer creates a new Timer that will send the current time on its channel after at least duration d.

func (Clock) Now

func (Clock) Now() Time

Now returns the current local time.

func (Clock) Parse

func (Clock) Parse(layout, value string) (Time, error)

See time.Parse.

func (Clock) ParseDuration

func (Clock) ParseDuration(s string) (Duration, error)

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

func (Clock) ParseInLocation(layout, value string, loc *Location) (Time, error)

See time.ParseInLocation.

func (Clock) Seconds

func (Clock) Seconds(n float64) Duration

Seconds returns a Duration value representing n Seconds.

func (Clock) Since

func (Clock) Since(t Time) Duration

Since returns the time elapsed since t. It is shorthand for clock.Now().Sub(t).

func (Clock) Sleep

func (Clock) Sleep(d Duration)

Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.

func (Clock) Tick

func (Clock) Tick(d Duration) <-chan Time

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.

func (Clock) Unix

func (Clock) Unix(sec int64, nsec int64) Time

See time.Unix.

func (Clock) UnixMicro

func (Clock) UnixMicro(usec int64) Time

See time.UnixMicro.

func (Clock) UnixMilli

func (Clock) UnixMilli(msec int64) Time

See time.UnixMilli.

func (Clock) UnixNano

func (Clock) UnixNano(nsec int64) Time

UnixNano is equivalent to clock.Unix(0, nsec).

func (Clock) Until

func (Clock) Until(t Time) Duration

Until returns the duration until t. It is shorthand for t.Sub(clock.Now()).

type Duration

type Duration = time.Duration

See time.Duration.

type Location

type Location = time.Location

See time.Location.

type Month

type Month = time.Month

See time.Month.

type ParseError

type ParseError = time.ParseError

See time.ParseError.

type Ticker

type Ticker struct {
	*time.Ticker
}

Ticker wraps time.Ticker to provide an interfaceable implementation.

func (*Ticker) C

func (t *Ticker) C() <-chan Time

C returns the channel on which the ticks are delivered.

type Time

type Time = time.Time

See time.Time.

type Timer

type Timer struct {
	*time.Timer
}

Timer wraps time.Timer to provide an interfaceable implementation.

func (*Timer) C

func (t *Timer) C() <-chan Time

C returns the channel on which the ticks are delivered.

type Weekday

type Weekday = time.Weekday

See time.Weekday.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL