add message.Time()
parent
83c8fccb78
commit
04c7a5c9e1
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
|
|
@ -23,6 +24,10 @@ func (m Message) Empty() bool {
|
||||||
return m == (Message{})
|
return m == (Message{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Message) Time() time.Time {
|
||||||
|
return time.Unix(int64(m.TS), 0)
|
||||||
|
}
|
||||||
|
|
||||||
func (m Message) Serialize() []byte {
|
func (m Message) Serialize() []byte {
|
||||||
b, err := json.Marshal(m)
|
b, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ func TestParseSlackTestdata(t *testing.T) {
|
||||||
if got != want.message {
|
if got != want.message {
|
||||||
t.Errorf("wanted \n\t%+v, got\n\t%+v", want.message, got)
|
t.Errorf("wanted \n\t%+v, got\n\t%+v", want.message, got)
|
||||||
}
|
}
|
||||||
|
if time := got.Time(); time.Unix() != int64(got.TS) {
|
||||||
|
t.Error("not unix time", got.TS, time)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue