From 5e4da01c3ae3ae2e870faba9085d9d9213c01c29 Mon Sep 17 00:00:00 2001 From: r Date: Fri, 13 Dec 2019 18:08:26 +0000 Subject: Initial commit --- mastodon/unixtime.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mastodon/unixtime.go (limited to 'mastodon/unixtime.go') diff --git a/mastodon/unixtime.go b/mastodon/unixtime.go new file mode 100644 index 0000000..a935a9e --- /dev/null +++ b/mastodon/unixtime.go @@ -0,0 +1,20 @@ +package mastodon + +import ( + "strconv" + "time" +) + +type Unixtime time.Time + +func (t *Unixtime) UnmarshalJSON(data []byte) error { + if len(data) > 0 && data[0] == '"' && data[len(data)-1] == '"' { + data = data[1 : len(data)-1] + } + ts, err := strconv.ParseInt(string(data), 10, 64) + if err != nil { + return err + } + *t = Unixtime(time.Unix(ts, 0)) + return nil +} -- cgit v1.2.3