Skip to content

Commit

Permalink
Fix marshalling time.Time{} to uint64 (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
aymkhalil authored Oct 25, 2022
1 parent 77c7ccb commit 0b0720a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pulsar/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (

// TimestampMillis return a time unix nano.
func TimestampMillis(t time.Time) uint64 {
// calling UnixNano on the zero Time is undefined
if t.IsZero() {
return 0
}
return uint64(t.UnixNano()) / uint64(time.Millisecond)
}

Expand Down
5 changes: 5 additions & 0 deletions pulsar/internal/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ func TestParseRelativeTimeInSeconds(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, time.Duration(10)*time.Hour*24*7*365, timestamp)
}

func TestTimestampMillis(t *testing.T) {
assert.Equal(t, uint64(0), TimestampMillis(time.Time{}))
assert.Equal(t, uint64(7), TimestampMillis(time.Unix(0, 7*int64(time.Millisecond))))
}

0 comments on commit 0b0720a

Please sign in to comment.