Skip to content

Commit 22ebfef

Browse files
Assignment timestamp in RFC 3339 format. (FF-2082) (#39)
1 parent 66c5367 commit 22ebfef

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

eppoclient/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"errors"
77
"fmt"
8-
"time"
98
)
109

1110
// Client for eppo.cloud. Instance of this struct will be created on calling InitClient.
@@ -118,7 +117,7 @@ func (ec *EppoClient) getAssignment(subjectKey string, flagKey string, subjectAt
118117
Allocation: rule.AllocationKey,
119118
Variation: assignedVariation,
120119
Subject: subjectKey,
121-
Timestamp: time.Now().String(),
120+
Timestamp: TimeNow(),
122121
SubjectAttributes: subjectAttributes,
123122
}
124123
ec.logger.LogAssignment(assignmentEvent)

eppoclient/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"strconv"
7+
"time"
78
)
89

910
type dictionary map[string]interface{}
@@ -50,3 +51,7 @@ func ToFloat64(val interface{}) (float64, error) {
5051
return 0, errors.New("value is neither a float64 nor a convertible string")
5152
}
5253
}
54+
55+
func TimeNow() string {
56+
return time.Now().UTC().Format(time.RFC3339)
57+
}

eppoclient/utils_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package eppoclient
22

33
import (
44
"testing"
5+
"time"
56
)
67

78
func TestToFloat64(t *testing.T) {
@@ -32,3 +33,11 @@ func TestToFloat64(t *testing.T) {
3233
})
3334
}
3435
}
36+
37+
func TestTimeNow(t *testing.T) {
38+
result := TimeNow()
39+
_, err := time.Parse(time.RFC3339, result)
40+
if err != nil {
41+
t.Errorf("TimeNow() = %v, want %v", result, "")
42+
}
43+
}

0 commit comments

Comments
 (0)