package timetools
import "github.com/mailgun/timetools"
Index ¶
- func AdvanceTimeBy(st TimeProvider, d time.Duration)
- type FreezedTime
- func (t *FreezedTime) After(d time.Duration) <-chan time.Time
- func (t *FreezedTime) Sleep(d time.Duration)
- func (t *FreezedTime) UtcNow() time.Time
- type RFC2822Time
- func NewRFC2822Time(timestamp int64) RFC2822Time
- func (t RFC2822Time) GetBSON() (interface{}, error)
- func (t RFC2822Time) IsZero() bool
- func (t RFC2822Time) MarshalJSON() ([]byte, error)
- func (t *RFC2822Time) SetBSON(raw bson.Raw) error
- func (t RFC2822Time) String() string
- func (t RFC2822Time) Unix() int64
- func (t *RFC2822Time) UnmarshalJSON(s []byte) error
- type RealTime
- func (*RealTime) After(d time.Duration) <-chan time.Time
- func (*RealTime) Sleep(d time.Duration)
- func (*RealTime) UtcNow() time.Time
- type TimeProvider
Functions ¶
func AdvanceTimeBy ¶
func AdvanceTimeBy(st TimeProvider, d time.Duration)
AdvanceTimeBy simulates advancing time by some time.Duration d. This function panics if st is not the result of a call to SleepProvider.
Types ¶
type FreezedTime ¶
FreezedTime is manually controlled time for use in tests.
func (*FreezedTime) After ¶
func (t *FreezedTime) After(d time.Duration) <-chan time.Time
func (*FreezedTime) Sleep ¶
func (t *FreezedTime) Sleep(d time.Duration)
func (*FreezedTime) UtcNow ¶
func (t *FreezedTime) UtcNow() time.Time
type RFC2822Time ¶
We use RFC2822 format for timestamps everywhere ('Thu, 13 Oct 2011 18:02:00 GMT'), but by default Go's JSON package uses another format when decoding/encoding timestamps. That's why we declare our own timestamp type and implement its marshal/unmarshal methods so JSON package decodes/encodes it properly.
func NewRFC2822Time ¶
func NewRFC2822Time(timestamp int64) RFC2822Time
func (RFC2822Time) GetBSON ¶
func (t RFC2822Time) GetBSON() (interface{}, error)
func (RFC2822Time) IsZero ¶
func (t RFC2822Time) IsZero() bool
func (RFC2822Time) MarshalJSON ¶
func (t RFC2822Time) MarshalJSON() ([]byte, error)
func (*RFC2822Time) SetBSON ¶
func (t *RFC2822Time) SetBSON(raw bson.Raw) error
func (RFC2822Time) String ¶
func (t RFC2822Time) String() string
func (RFC2822Time) Unix ¶
func (t RFC2822Time) Unix() int64
func (*RFC2822Time) UnmarshalJSON ¶
func (t *RFC2822Time) UnmarshalJSON(s []byte) error
type RealTime ¶
type RealTime struct { }
RealTime is a real clock time, used in production.
func (*RealTime) After ¶
func (*RealTime) Sleep ¶
func (*RealTime) UtcNow ¶
type TimeProvider ¶
type TimeProvider interface { UtcNow() time.Time Sleep(time.Duration) After(time.Duration) <-chan time.Time }
TimeProvider is an interface we use to mock time in tests.
func SleepProvider ¶
func SleepProvider(currentTime time.Time) TimeProvider
SleepProvider returns a TimeProvider that has good fakes for time.Sleep and time.After. Both functions will behave as if time is frozen until you call AdvanceTimeBy, at which point any calls to time.Sleep that should return do return and any ticks from time.After that should happen do happen.
Source Files ¶
- Version
- v0.0.0-20170619190023-f3a7b8ffff47 (latest)
- Published
- Jun 19, 2017
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 5 months ago –
Tools for package owners.