From ebf4c235c4a04dbad3380631f96ec6b3b6681cb0 Mon Sep 17 00:00:00 2001 From: MaryamTaj Date: Sun, 29 Sep 2024 17:41:36 -0400 Subject: [PATCH] Updating to_event_go so it serializes time correctly Signed-off-by: MaryamTaj --- v2/binding/to_event.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/v2/binding/to_event.go b/v2/binding/to_event.go index d3332c158..1c73b3c5b 100644 --- a/v2/binding/to_event.go +++ b/v2/binding/to_event.go @@ -12,6 +12,7 @@ import ( "errors" "fmt" "io" + "time" "github.com/cloudevents/sdk-go/v2/binding/format" "github.com/cloudevents/sdk-go/v2/binding/spec" @@ -138,6 +139,16 @@ func (b *messageToEventBuilder) SetAttribute(attribute spec.Attribute, value int } return nil } + + // Check if the attribute is 'time' and set it correctly + if attribute.Kind() == spec.Time { + t, ok := value.(time.Time) + if !ok { + return fmt.Errorf("expected time.Time for 'time' attribute, got %T", value) + } + return attribute.Set(b.Context, t) + } + return attribute.Set(b.Context, value) }