From 69ba54ae2b5702deb34abe060650916972b09d40 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Thu, 6 Apr 2023 09:00:06 -0700 Subject: [PATCH] rest/models: print out timestamps in more appealing format Previously if you printed a models.Millis with `%#v` you would get something that looked like this: models.Millis{wall:0x0, ext:63816264000, loc:(*time.Location)(0x105256980) Which doesn't tell you at a glance what time it represents. This change makes it print out a prettier looking string that tells you what time it represents. Millis(time.Date(2023, time.April, 3, 21, 0, 0, 0, time.Local) I previously merged the same change to the Go standard library. --- rest/models/types.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rest/models/types.go b/rest/models/types.go index 7784fe43..8d55cdc0 100644 --- a/rest/models/types.go +++ b/rest/models/types.go @@ -253,6 +253,12 @@ func (m *Millis) MarshalJSON() ([]byte, error) { return json.Marshal(time.Time(*m).UnixMilli()) } +// GoString implements fmt.GoStringer and formats m to be printed in Go source +// code. +func (m Millis) GoString() string { + return "Millis(" + time.Time(m).GoString() + ")" +} + // Nanos represents a Unix time in nanoseconds since January 1, 1970 UTC. type Nanos time.Time