ctxtime

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: LGPL-3.0 Imports: 2 Imported by: 1

README

PkgGoDev

CtxTime

The ctxtime package is a simple package for accessing the current time with a context-based method for overriding the system time where necessary, for example in tests.

Documentation

Overview

Package ctxtime provides access to either the current time, or a time that has been cached in a context. It is intended to provide consistent time information in tests and other similar situation whilst being as unintrusive as possible.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTime

func ContextWithTime(ctx context.Context, t time.Time) context.Context

ContextWithTime attaches the given time to a context. All subsequent calls to Now will return this time. If the given time is the zero time, then Now will return the system time.

It is expected that ContextWithTime is most useful for having consistent times in tests.

func Now

func Now(ctx context.Context) time.Time

Now determines the current time. If a non-zero time has been added to the given context using ContextWithTime then this time will be returned, otherwise the value of time.Now will be used.

func UTCMilliseconds

func UTCMilliseconds(ctx context.Context) time.Time

UTCMilliseconds is a convenience funtion that returns the time returned by Now, but in the UTC time zone and rounded to the nearest millisecond.

func UTCSeconds

func UTCSeconds(ctx context.Context) time.Time

UTCSeconds is a convenience funtion that returns the time returned by Now, but in the UTC time zone and rounded to the nearest second.

Types

This section is empty.

Jump to

Keyboard shortcuts

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