timey

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDays

func AddDays(t time.Time, n int) time.Time

AddDays adds the given number of days to the given time

func AddHours

func AddHours(t time.Time, n int) time.Time

AddHours adds the given number of hours to the given time

func AddMonths

func AddMonths(t time.Time, n int) time.Time

AddMonths adds the given number of months to the given time

func DiffEqual

func DiffEqual(d time.Duration, t0 time.Time, ts ...time.Time) bool

DiffEqual returns true if all ts inputs are within duration d range of t0.

func DurationAbs

func DurationAbs(d time.Duration) time.Duration

DurationAbs returns the absolute (positive) value of a time.Duration.

func Pointer

func Pointer(v time.Time) *time.Time

Pointer returns a pointer to the given time.Time. NOTE: this method is deprecated. Use helpy.Pointer instead.

func TimeOrDefault

func TimeOrDefault(v *time.Time, defaultVal time.Time) *time.Time

TimeOrDefault returns time.Time if it is not nil, and a pointer to defaultVal otherwise. NOTE: this method is deprecated. Use helpy.DerefOrValue instead.

func TruncEqual

func TruncEqual(d time.Duration, t0 time.Time, ts ...time.Time) bool

TruncEqual truncates t0 and ts inputs down to a multiple of d (since the zero time) and returns true if all ts are equal to t0.

Types

type MockTime added in v0.1.13

type MockTime struct {
	Time time.Time
}

MockTime helps mock time for functions that take a func() time.Time argument to retrieve the time, instead of using the global time.Now(). This is especially useful when testing functions that depend on time.

func NewMockTime added in v0.1.13

func NewMockTime(now *time.Time) *MockTime

NewMockTime returns a MockTime with the given time.Time instance. If now is nil, it will default to time.Now().

func (*MockTime) Add added in v0.1.13

func (mt *MockTime) Add(d time.Duration) time.Time

Add adds d to the current (mocked) time and returns the resulting time.

func (*MockTime) Now added in v0.1.13

func (mt *MockTime) Now() time.Time

Now returns the current (mocked) time.

Jump to

Keyboard shortcuts

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