Skip to content

Commit dbff937

Browse files
MaryamTajduglin
authored andcommitted
BREAKING CHANGE:Serializing time to RFC-3339
don't truncate to seconds Signed-off-by: MaryamTaj <[email protected]>
1 parent 74ac76d commit dbff937

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

test/integration/http/direct_v1_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
cloudevents "github.com/cloudevents/sdk-go/v2"
16-
"github.com/cloudevents/sdk-go/v2/types"
1716
)
1817

1918
func TestSenderReceiver_binary_v1(t *testing.T) {
@@ -101,7 +100,6 @@ func TestSenderReceiver_binary_v1(t *testing.T) {
101100

102101
func TestSenderReceiver_structured_v1(t *testing.T) {
103102
now := time.Now()
104-
105103
testCases := DirectTapTestCases{
106104
"Structured v1.0": {
107105
now: now,
@@ -131,7 +129,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
131129
Header: map[string][]string{
132130
"content-type": {"application/cloudevents+json"},
133131
},
134-
Body: fmt.Sprintf(`{"data":{"hello":"unittest"},"id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, types.FormatTime(now.UTC())),
132+
Body: fmt.Sprintf(`{"data":{"hello":"unittest"},"id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.Format(time.RFC3339)),
135133
ContentLength: 182,
136134
},
137135
},
@@ -177,7 +175,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
177175
Header: map[string][]string{
178176
"content-type": {"application/cloudevents+json"},
179177
},
180-
Body: fmt.Sprintf(`{"data_base64":"aGVsbG86IHVuaXR0ZXN0","id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.UTC().Format(time.RFC3339Nano)),
178+
Body: fmt.Sprintf(`{"data_base64":"aGVsbG86IHVuaXR0ZXN0","id":"ABC-123","source":"/unit/test/client","specversion":"1.0","subject":"resource","time":%q,"type":"unit.test.client.sent"}`, now.Format(time.RFC3339)),
181179
ContentLength: 191,
182180
},
183181
},

v2/event/event_marshal.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"slices"
1414
"strings"
15+
"time"
1516

1617
jsoniter "github.com/json-iterator/go"
1718
)
@@ -77,7 +78,7 @@ func WriteJson(in *Event, writer io.Writer) error {
7778
if eventContext.Time != nil {
7879
stream.WriteMore()
7980
stream.WriteObjectField("time")
80-
stream.WriteString(eventContext.Time.String())
81+
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
8182
}
8283
case *EventContextV1:
8384
// Set a bunch of variables we need later
@@ -121,7 +122,7 @@ func WriteJson(in *Event, writer io.Writer) error {
121122
if eventContext.Time != nil {
122123
stream.WriteMore()
123124
stream.WriteObjectField("time")
124-
stream.WriteString(eventContext.Time.String())
125+
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
125126
}
126127
default:
127128
return fmt.Errorf("missing event context")

0 commit comments

Comments
 (0)