diff --git a/pkg/cloudevents/transport/amqp/codec.go b/pkg/cloudevents/transport/amqp/codec.go index 4498318bd..e403c8d37 100644 --- a/pkg/cloudevents/transport/amqp/codec.go +++ b/pkg/cloudevents/transport/amqp/codec.go @@ -196,17 +196,17 @@ func (c Codec) fromHeaders(h map[string]interface{}, event *cloudevents.Event) e } delete(h, prefix+"source") - if t, ok := h[prefix+"time"].(string); ok { // TODO: time can be empty - timestamp := types.ParseTimestamp(t) - if err := ec.SetTime(timestamp.Time); err != nil { - return err + if t, ok := h[prefix+"time"].(string); ok { + if timestamp := types.ParseTimestamp(t); timestamp != nil { + if err := ec.SetTime(timestamp.Time); err != nil { + return err + } } } delete(h, prefix+"time") - if t, ok := h[prefix+"schemaurl"].(string); ok { - timestamp := types.ParseTimestamp(t) - if err := ec.SetTime(timestamp.Time); err != nil { + if s, ok := h[prefix+"schemaurl"].(string); ok { + if err := ec.SetSchemaURL(s); err != nil { return err } } diff --git a/pkg/cloudevents/transport/pubsub/codec.go b/pkg/cloudevents/transport/pubsub/codec.go index 98b3d7755..cb9d76606 100644 --- a/pkg/cloudevents/transport/pubsub/codec.go +++ b/pkg/cloudevents/transport/pubsub/codec.go @@ -187,16 +187,16 @@ func (c Codec) fromAttributes(a map[string]string, event *cloudevents.Event) err delete(a, prefix+"source") if t := a[prefix+"time"]; t != "" { - timestamp := types.ParseTimestamp(t) - if err := ec.SetTime(timestamp.Time); err != nil { - return err + if timestamp := types.ParseTimestamp(t); timestamp != nil { + if err := ec.SetTime(timestamp.Time); err != nil { + return err + } } } delete(a, prefix+"time") - if t := a[prefix+"schemaurl"]; t != "" { - timestamp := types.ParseTimestamp(t) - if err := ec.SetTime(timestamp.Time); err != nil { + if s := a[prefix+"schemaurl"]; s != "" { + if err := ec.SetSchemaURL(s); err != nil { return err } }