add message.Time()

main
Bel LaPointe 2024-04-12 13:01:42 -06:00
parent 83c8fccb78
commit 04c7a5c9e1
2 changed files with 8 additions and 0 deletions

View File

@ -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 {

View File

@ -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)
}
}) })
}) })
} }