aboutsummaryrefslogtreecommitdiff
path: root/mastodon/unixtime.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-13 18:08:26 +0000
committerr <r@freesoftwareextremist.com>2019-12-13 18:26:24 +0000
commit5e4da01c3ae3ae2e870faba9085d9d9213c01c29 (patch)
tree39d6f1e76b901549f194ddbac3c6cb82e0abd019 /mastodon/unixtime.go
downloadbloat-5e4da01c3ae3ae2e870faba9085d9d9213c01c29.tar.gz
bloat-5e4da01c3ae3ae2e870faba9085d9d9213c01c29.zip
Initial commit
Diffstat (limited to 'mastodon/unixtime.go')
-rw-r--r--mastodon/unixtime.go20
1 files changed, 20 insertions, 0 deletions
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
+}