Documentation
¶
Overview ¶
Package timejump allows you to mock `time.Now`.
Example ¶
package main import ( "fmt" "time" "github.com/agatan/timejump" ) func main() { timejump.Activate() defer timejump.Deactivate() future := time.Date(1985, 10, 26, 0, 0, 0, 0, time.UTC) timejump.Stop() timejump.Jump(future) fmt.Println(timejump.Now()) }
Output: 1985-10-26 00:00:00 +0000 UTC
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Activate ¶
func Activate()
Activate enables timejump's mocking functionality. Call this at the top of test functions.
func Deactivate ¶
func Deactivate()
Deactivate disables timejump's mocking functionality. Call this at the bottom of test functions (or use `defer` at the top).
func Move ¶
Move sets the location of the time generated by `Now`.
Example ¶
package main import ( "fmt" "time" "github.com/agatan/timejump" ) func main() { timejump.Activate() defer timejump.Deactivate() timejump.Move(time.FixedZone("test/zone", 123)) zone, offset := timejump.Now().Zone() fmt.Printf("zone: %v, offset: %v\n", zone, offset) }
Output: zone: test/zone, offset: 123
func Now ¶
Now returns the current time. If timejump is activated, it returns fake time calculated based on fake values set by `Jump`, `Move`, and `Scale`.
func Scale ¶
func Scale(n int)
Scale sets the scale of the world speed.
Example ¶
package main import ( "time" "github.com/agatan/timejump" ) func main() { timejump.Activate() defer timejump.Deactivate() now := timejump.Now() // Time passes 100 times faster. timejump.Scale(1000) // Sleep just a millisecond. time.Sleep(time.Millisecond) sub := timejump.Now().Sub(now) if sub.Seconds() < 1 { panic("1 second have passed while sleeping 1 millisecond in this world.") } }
Output:
Types ¶
This section is empty.