-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
62 lines (56 loc) · 927 Bytes
/
types.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package sfdc
import (
"encoding/json"
"time"
)
type Time struct {
time.Time
}
type Date struct {
time.Time
}
const iso8601Layout string = "2006-01-02T15:04:05Z0700"
func (t *Time) UnmarshalJSON(b []byte) error {
if len(b) == 0 {
return nil
}
var str string
err := json.Unmarshal(b, &str)
if err != nil {
return err
}
if str == "null" || str == "" {
return nil
}
r, err := time.Parse(time.RFC3339, str)
if err != nil {
r, err = time.Parse(iso8601Layout, str)
if err != nil {
return err
}
}
t.Time = r
return nil
}
func (d *Date) UnmarshalJSON(b []byte) error {
if len(b) == 0 {
return nil
}
var str string
err := json.Unmarshal(b, &str)
if err != nil {
return err
}
if str == "null" || str == "" {
return nil
}
r, err := time.Parse(time.RFC3339, str)
if err != nil {
r, err = time.Parse(time.DateOnly, str)
if err != nil {
return err
}
}
d.Time = r
return nil
}