On UNIX like operating systems there's a useful utility (faketime(1)) that allows executing a program by faking its clock time.
This is done by replacing a C library function with LD_PRELOAD. Of course go doesn't use the c library so the program fails.
This library implements a copy of "time.Now()" with the name "ftime.Now()". It works exactly same way "time.Now()" does but uses the command "date" to get the date and time when the LD_PRELOAD environment variable is set.
$ go build -o build/date-go ./cmd/date-go
$ faketime '2040-01-01' ./build/date-go time.Time
2023-11-05 15:48:40
$ faketime '2040-01-01' ./build/date-go ftime.Time
2040-01-01 00:00:00
package ftime // import "github.com/harkaitz/go-faketime"
func ClrTime()
func Now() (t time.Time)
func SetTime(t time.Time)
For making bug reports, feature requests and donations visit one of the following links:
- gemini://harkadev.com/oss/
- https://harkadev.com/oss/