Skip to content

Commit

Permalink
Fix timestamp formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
maximepeschard committed Jun 21, 2020
1 parent 9c264c0 commit ec473a7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions client/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"strings"
"time"
)

// Valid format string placeholders.
Expand All @@ -19,14 +20,13 @@ const (
// FormatterHelp returns a message describing format tokens.
func FormatterHelp() string {
var b strings.Builder
fmt.Fprint(&b, "* available format tokens :\n")
fmt.Fprintf(&b, "%s : topic\n", TopicPlaceholder)
fmt.Fprintf(&b, "%s : partition\n", PartitionPlaceholder)
fmt.Fprintf(&b, "%s : offset\n", OffsetPlaceholder)
fmt.Fprintf(&b, "%s : timestamp\n", TimestampPlaceholder)
fmt.Fprintf(&b, "%s : message key\n", KeyPlaceholder)
fmt.Fprintf(&b, "%s : message value\n", ValuePlaceholder)
fmt.Fprint(&b, "* example format string : 'received %v from %t'")
fmt.Fprintf(&b, "* %s : topic\n", TopicPlaceholder)
fmt.Fprintf(&b, "* %s : partition\n", PartitionPlaceholder)
fmt.Fprintf(&b, "* %s : offset\n", OffsetPlaceholder)
fmt.Fprintf(&b, "* %s : timestamp (epoch in milliseconds)\n", TimestampPlaceholder)
fmt.Fprintf(&b, "* %s : message key\n", KeyPlaceholder)
fmt.Fprintf(&b, "* %s : message value\n", ValuePlaceholder)
fmt.Fprint(&b, "(example format string : 'received %v from %t')")
return b.String()
}

Expand All @@ -46,7 +46,7 @@ func (f Formatter) Format(m Message) string {
TopicPlaceholder, m.Topic,
PartitionPlaceholder, strconv.FormatInt(int64(m.Partition), 10),
OffsetPlaceholder, strconv.FormatInt(m.Offset, 10),
TimestampPlaceholder, strconv.FormatInt(m.Timestamp.Unix(), 10),
TimestampPlaceholder, strconv.FormatInt(m.Timestamp.UnixNano()/int64(time.Millisecond), 10),
KeyPlaceholder, string(m.Key),
ValuePlaceholder, string(m.Value),
)
Expand Down

0 comments on commit ec473a7

Please sign in to comment.