timeutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package timeutil provides time.Now that can be monkey-patched.

Example
package main

import (
	"fmt"
	"time"

	"github.com/layer0-platform/webpackager/internal/timeutil"
)

func main() {
	defer timeutil.ResetNow()
	timeutil.StubNowWithFixedTime(time.Date(2020, time.June, 1, 12, 34, 56, 0, time.UTC))
	fmt.Println(timeutil.Now())
}
Output:

2020-06-01 12:34:56 +0000 UTC

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now() time.Time

Now returns the current local time. It is equal to time.Now by default but can be faked using StubNow or other Stub functions.

func ResetNow

func ResetNow()

ResetNow restores the Now's original behavior.

func StubNow

func StubNow(stub func() time.Time)

StubNow substitutes Now with stub for testing.

func StubNowToAdjust

func StubNowToAdjust(newNow time.Time)

StubNowToAdjust "adjusts" Now to newNow for testing. The stubbed time continues to advance: Now will return newNow plus the time elapsed since StubNowToAdjust is called.

func StubNowWithFixedTime

func StubNowWithFixedTime(newNow time.Time)

StubNowWithFixedTime makes Now return newNow for testing. The stubbed time does not advance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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