timex

package
v0.4.44 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package timex provides time functions via a struct.

This is intended to be paired with an interface for the used methods of the struct to be used in dependency injection. From there, a mock can be created for the interface, ensuring unit tests can use predictable times as needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct{}

Clock provides a wrapper around functions in time to support dependency injection and mocking in unit tests.

func NewClock

func NewClock() *Clock

NewClock creates a new Clock.

func (*Clock) Now

func (*Clock) Now() time.Time

Now returns the current time in the local timezone.

This should only be used to calculate the durations between 2 points in time via the Since and Until methods.

func (*Clock) Since

func (c *Clock) Since(t time.Time) time.Duration

Since returns the time elapsed since the given value.

func (*Clock) UTCNow

func (*Clock) UTCNow() time.Time

UTCNow returns the current time in UTC.

This should be used when storing the time. It must not be used for calculating the duration between 2 points in time as it lacks any monotonic representation.

func (*Clock) Until

func (c *Clock) Until(t time.Time) time.Duration

Until returns the duration until the given value.

Jump to

Keyboard shortcuts

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