Skip to content

Commit d7b6aff

Browse files
committed
don't truncate to seconds
Signed-off-by: Doug Davis <[email protected]>
1 parent 3c35d36 commit d7b6aff

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

test/integration/http/direct_v1_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
117117
Context: cloudevents.EventContextV1{
118118
ID: "ABC-123",
119119
Type: "unit.test.client.sent",
120-
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
120+
Time: &cloudevents.Timestamp{Time: now},
121121
Source: *cloudevents.ParseURIRef("/unit/test/client"),
122122
Subject: strptr("resource"),
123123
DataContentType: cloudevents.StringOfApplicationJSON(),
@@ -130,7 +130,7 @@ func TestSenderReceiver_structured_v1(t *testing.T) {
130130
Header: map[string][]string{
131131
"content-type": {"application/cloudevents+json"},
132132
},
133-
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.Truncate(time.Second).Format(time.RFC3339)),
133+
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)),
134134
ContentLength: 182,
135135
},
136136
},
@@ -163,7 +163,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
163163
Context: cloudevents.EventContextV1{
164164
ID: "ABC-123",
165165
Type: "unit.test.client.sent",
166-
Time: &cloudevents.Timestamp{Time: now.Truncate(time.Second)},
166+
Time: &cloudevents.Timestamp{Time: now},
167167
Source: *cloudevents.ParseURIRef("/unit/test/client"),
168168
Subject: strptr("resource"),
169169
DataContentType: cloudevents.StringOfTextPlain(),
@@ -176,7 +176,7 @@ func TestSenderReceiver_data_base64_v1(t *testing.T) {
176176
Header: map[string][]string{
177177
"content-type": {"application/cloudevents+json"},
178178
},
179-
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.Truncate(time.Second).Format(time.RFC3339)),
179+
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)),
180180
ContentLength: 191,
181181
},
182182
},

v2/event/event_marshal.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func WriteJson(in *Event, writer io.Writer) error {
7777
if eventContext.Time != nil {
7878
stream.WriteMore()
7979
stream.WriteObjectField("time")
80-
stream.WriteString(eventContext.Time.Format(time.RFC3339))
80+
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
8181
}
8282
case *EventContextV1:
8383
// Set a bunch of variables we need later
@@ -121,7 +121,7 @@ func WriteJson(in *Event, writer io.Writer) error {
121121
if eventContext.Time != nil {
122122
stream.WriteMore()
123123
stream.WriteObjectField("time")
124-
stream.WriteString(eventContext.Time.Format(time.RFC3339))
124+
stream.WriteString(eventContext.Time.Format(time.RFC3339Nano))
125125
}
126126
default:
127127
return fmt.Errorf("missing event context")

0 commit comments

Comments
 (0)