You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2022/10/25 08:25:21 UTC

[pulsar-client-go] branch master updated: Fix marshalling time.Time{} to uint64 (#865)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b0720a  Fix marshalling time.Time{} to uint64 (#865)
0b0720a is described below

commit 0b0720ab73d7f6378b8b6ac37acbafe547c268c8
Author: Ayman Khalil <ay...@gmail.com>
AuthorDate: Tue Oct 25 01:25:14 2022 -0700

    Fix marshalling time.Time{} to uint64 (#865)
---
 pulsar/internal/utils.go      | 4 ++++
 pulsar/internal/utils_test.go | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/pulsar/internal/utils.go b/pulsar/internal/utils.go
index 0763ced..e4a4994 100644
--- a/pulsar/internal/utils.go
+++ b/pulsar/internal/utils.go
@@ -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)
 }
 
diff --git a/pulsar/internal/utils_test.go b/pulsar/internal/utils_test.go
index 65babd0..90d6f2d 100644
--- a/pulsar/internal/utils_test.go
+++ b/pulsar/internal/utils_test.go
@@ -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))))
+}