~samwhited/paddle

ref: v0.0.3 paddle/time.go -rw-r--r-- 615 bytes
fa35a6a5Sam Whited paddle: add note about maintenance status 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package paddle

import (
	"encoding/json"
	"time"

	"code.soquee.net/paddle/internal"
)

// Time is a custom time type that supports marshaling and unmarshaling Paddle's
// custom time format that ignores the standard JSON format.
type Time time.Time

var _ json.Unmarshaler = (*Time)(nil)

// UnmarshalJSON satisfies the json.Unmarshaler interface for Time.
func (t *Time) UnmarshalJSON(b []byte) error {
	newTime, err := time.Parse(internal.DateFmt, string(b))
	if err != nil {
		newTime, err = time.Parse(internal.DateTimeFmt, string(b))
		if err != nil {
			return err
		}
	}

	*t = Time(newTime)
	return nil
}