Skip to content

Commit 2d2e620

Browse files
committed
unmarshal times correctly
1 parent 07acd2e commit 2d2e620

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

observation/observation.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,20 @@ func (o *Observation) MarshalJSON() ([]byte, error) {
3535
Alias: (*Alias)(o),
3636
})
3737
}
38+
39+
func (o *Observation) UnmarshalJSON(data []byte) error {
40+
type Alias Observation
41+
tmp := &struct {
42+
FirstSeen int64 `json:"time_first"`
43+
LastSeen int64 `json:"time_last"`
44+
*Alias
45+
}{
46+
Alias: (*Alias)(o),
47+
}
48+
if err := json.Unmarshal(data, &tmp); err != nil {
49+
return err
50+
}
51+
o.FirstSeen = time.Unix(tmp.FirstSeen, 0)
52+
o.LastSeen = time.Unix(tmp.LastSeen, 0)
53+
return nil
54+
}

0 commit comments

Comments
 (0)