timeproxy

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 1 Imported by: 9

Documentation

Overview

Package timeproxy contains functions and data types for working with time. The package exists so that time functionality can be mocked in tests.

Index

Constants

View Source
const (
	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"
	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"
)
View Source
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

func After(d Duration) <-chan Time

After calls TimeProxy.After

func Sleep

func Sleep(d Duration)

Sleep calls TimeProxy.Sleep

func Tick

func Tick(d Duration) <-chan Time

Tick calls TimeProxy.Tick

Types

type Duration

type Duration = time.Duration

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration calls time.ParseDuration

func Since

func Since(t Time) Duration

Since calls TimeProxy.Since

func Until

func Until(t Time) Duration

Until calls TimeProxy.Until

type Location

type Location = time.Location
var (
	Local *Location = time.Local
	UTC   *Location = time.UTC
)

func FixedZone

func FixedZone(name string, offset int) *Location

FixedZone calls time.FixedZone

func LoadLocation

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

LoadLocation calls time.LoadLocation

func LoadLocationFromTZData

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

LoadLocationFromTZData calls time LoadLocationFromTZData

type Month

type Month = time.Month
const (
	January Month = 1 + iota
	February
	March
	April
	May
	June
	July
	August
	September
	October
	November
	December
)

type ParseError

type ParseError = time.ParseError

type Proxy

type Proxy interface {
	Now() Time
	Tick(Duration) <-chan Time
	After(Duration) <-chan Time
	Sleep(Duration)
	NewTicker(Duration) *Ticker
	AfterFunc(Duration, func()) *Timer
	NewTimer(Duration) *Timer
	Since(Time) Duration
	Until(Time) Duration
}

Proxy is a proxy for the time package. By default, the methods from stdlib are called.

var TimeProxy Proxy = RealTime{}

TimeProxy is an interface that maps 1:1 with the standalone functions in this pacakge. By default, TimeProxy uses the functions from the time package in the standard library.

Replace TimeProxy with a different implementation to gain control over time in tests.

type RealTime

type RealTime struct{}

RealTime dispatches all calls to the stdlib time package

func (RealTime) After

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

After calls time.After

func (RealTime) AfterFunc

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

AfterFunc calls time.AfterFunc

func (RealTime) NewTicker

func (RealTime) NewTicker(d Duration) *Ticker

NewTicker calls time.NewTicker

func (RealTime) NewTimer

func (RealTime) NewTimer(d Duration) *Timer

NewTimer calls time.NewTimer. It returns a timeproxy Timer with StopFunc set to the timer's Stop method and ResetFunc set to the timer's Reset method.

func (RealTime) Now

func (RealTime) Now() Time

Now calls time.Now

func (RealTime) Since

func (RealTime) Since(t Time) Duration

Since calls time.Since

func (RealTime) Sleep

func (RealTime) Sleep(d Duration)

Sleep calls time.Sleep

func (RealTime) Tick

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

Tick calls time.Tick

func (RealTime) Until

func (RealTime) Until(t Time) Duration

Until calls time.Until

type Ticker

type Ticker struct {
	C        <-chan Time
	StopFunc func()
}

Ticker is an abstraction of time.Ticker that can be patched more easily.

func NewTicker

func NewTicker(d Duration) *Ticker

NewTicker calls TimeProxy.NewTicker

func (*Ticker) Stop

func (t *Ticker) Stop()

type Time

type Time = time.Time

func Date

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

Date calls time.Date

func Now

func Now() Time

Now calls TimeProxy.Now

func Parse

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

Parse calls time.Parse

func ParseInLocation

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

ParseInLocation calls time.ParseInLocation

func Unix

func Unix(sec, nsec int64) Time

Unix calls time.Unix

type Timer

type Timer struct {
	C         <-chan Time
	ResetFunc func(Duration) bool
	StopFunc  func() bool
}

Timer is an abstraction of time.Timer that can be patched more easily.

func NewTimer

func NewTimer(d Duration) *Timer

NewTimer returns TimeProxy.NewTimer

func (*Timer) Reset

func (t *Timer) Reset(d Duration) bool

Reset calls t.ResetFunc

func (*Timer) Stop

func (t *Timer) Stop() bool

Stop calls t.StopFunc

type Weekday

type Weekday = time.Weekday
const (
	Sunday Weekday = iota
	Monday
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL