aboutsummaryrefslogtreecommitdiff
path: root/mastodon/unixtime.go
blob: a935a9e655d4973b28739c03fd44ce7fc97f3378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
}