Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from PaulAnnekov/fix-timestamp-ms
Browse files Browse the repository at this point in the history
Fixed TimeStamp resolution
  • Loading branch information
m90 committed Dec 25, 2018
2 parents 7f22c60 + 5c8c750 commit a075777
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client_test.go
Expand Up @@ -17,7 +17,7 @@ func TestNewClient(t *testing.T) {
func TestMessage_Client(t *testing.T) {
oldTimeStamp := TimeStamp
defer func() { TimeStamp = oldTimeStamp }()
TimeStamp = func() int { return 998877 }
TimeStamp = func() int64 { return 998877 }
c := New("foo-bar-baz")

t.Run("default", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions event.go
Expand Up @@ -16,14 +16,14 @@ type Event struct {
APIKey string `json:"api_key"`
UserID string `json:"user_id"`
Intent string `json:"intent"`
TimeStamp int `json:"timestamp_millis,omitempty"`
TimeStamp int64 `json:"timestamp_millis,omitempty"`
Platform string `json:"platform,omitempty"`
Version string `json:"version,omitempty"`
Properties []EventProperty `json:"properties"`
}

// SetTimeStamp adds an optional "timestamp" value to the event
func (e *Event) SetTimeStamp(t int) *Event {
func (e *Event) SetTimeStamp(t int64) *Event {
e.TimeStamp = t
return e
}
Expand Down
4 changes: 2 additions & 2 deletions message.go
Expand Up @@ -50,7 +50,7 @@ type Message struct {
APIKey string `json:"api_key"`
Type MessageType `json:"type"`
UserID string `json:"user_id"`
TimeStamp int `json:"time_stamp"`
TimeStamp int64 `json:"time_stamp"`
Platform string `json:"platform"`
Message string `json:"message,omitempty"`
Intent string `json:"intent,omitempty"`
Expand Down Expand Up @@ -90,7 +90,7 @@ func (m *Message) SetVersion(v string) *Message {
}

// SetTimeStamp overrides the message's "timestamp" value
func (m *Message) SetTimeStamp(t int) *Message {
func (m *Message) SetTimeStamp(t int64) *Message {
m.TimeStamp = t
return m
}
Expand Down
4 changes: 2 additions & 2 deletions timestamp.go
Expand Up @@ -5,6 +5,6 @@ import (
)

// TimeStamp returns the current time in UNIX milliseconds
var TimeStamp = func() int {
return int(time.Now().Unix())
var TimeStamp = func() int64 {
return time.Now().UnixNano()/1e6
}
4 changes: 2 additions & 2 deletions timestamp_test.go
Expand Up @@ -5,8 +5,8 @@ import "testing"
func TestTimeStamp(t *testing.T) {
t.Run("default", func(t *testing.T) {
result := TimeStamp()
if result <= 0 {
t.Errorf("Expected non-zero timestamp, got %v", result)
if result < 10000000000 {
t.Errorf("Expected non-zero timestamp in milliseconds, got %v", result)
}
})
}

0 comments on commit a075777

Please sign in to comment.