tummy

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: 0BSD Imports: 1 Imported by: 0

README

Tummy Time ⏳

License Coverage GitHub Workflow Status Go Report Card Go PKG

Tummy is a Go library that provides a simple way to manipulate time in your tests.
It allows you to control the flow of time, making it easier to test time-dependent code.

go get github.com/rakunlabs/tummy

Usage

// enable tummy time manipulation, usually in the test setup
tummy.Enable()

tummy.SetTime(time.Date(1919, 5, 19, 12, 0, 0, 0, time.UTC))

fmt.Println("Current time:", tummy.Now())
// Current time: 1919-05-19 12:00:00.000000119 +0000 UTC

tummy.AddDuration(2 * time.Hour)
fmt.Println("After 2 hours:", tummy.Now())
// After 2 hours: 1919-05-19 14:00:00.000019847 +0000 UTC

tummy.AddDate(4, 4, 4)
fmt.Println("After 1 day:", tummy.Now())
// After 1 day: 1923-10-23 14:00:00.000015641 +0000 UTC

Documentation

Overview

Example
package main

import (
	"fmt"
	"time"

	"github.com/rakunlabs/tummy"
)

func main() {
	tummy.Enable()

	tummy.SetTime(time.Date(1919, 5, 19, 12, 0, 0, 0, time.UTC))

	tummy.AddDuration(2 * time.Hour)
	fmt.Println(tummy.Now().Hour()) // 14

	tummy.AddDate(0, 0, 1)
	fmt.Println(tummy.Now().Day()) // 20

}
Output:
14
20

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Now = time.Now
)

Functions

func AddDate

func AddDate(years int, months int, days int)

AddDate adds years, months, and days to the global tummy.Now.

func AddDuration

func AddDuration(d time.Duration)

AddDuration adds a duration to the global tummy.Now.

func Disable

func Disable()

Disable resets the global tummy.Now to the original time.Now function.

func Enable

func Enable()

Enable sets the global time.Now to a custom tummy.Now function.

func SetTime

func SetTime(t time.Time)

SetTime sets the global tummy.Now to a specific time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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