Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace time.Time.String() with time.Time.Format() #1017

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MaryamTaj
Copy link

Resolves #987
Earlier, we used time.Time.String() to marshal time into a string. According to the go time.Time documentation however, time.Time.String() is only suitable for debugging purposes. This PR replaces time.Time.String with time.Time.Format() with RFC3339 to provide a stable serialized representation of time.

@@ -6,6 +6,7 @@ on:
- 'protocol/**' # Push events to matching protocol/foo/bar/v*, i.e. protocol/foo/bar/v1.0, protocol/foo/bar/v20.15.10
- 'observability/**' # Push events to matching observability/foo/bar/v*
- 'sql/**' # Push events to matching sql/v*
- 'binding/**' # Push events to matching binding/foo/bar/v*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be separate PR

README.md Outdated
@@ -27,7 +27,7 @@ _Note:_ Supported go version: 1.14+
Add the module as dependency using go mod:

```shell
go get github.com/cloudevents/sdk-go/v2@v2.4.1
go get github.com/cloudevents/sdk-go/v2@v2.5.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be separate PR (incl. the other ones)

Comment on lines 1 to 5
/*
Copyright 2021 The CloudEvents Authors
SPDX-License-Identifier: Apache-2.0
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be separate PR

Comment on lines -79 to +80
stream.WriteString(eventContext.Time.String())
stream.WriteString(eventContext.Time.Format(time.RFC3339))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran an example w/ Go 1.22 (same w/ Go 1.21) here: https://go.dev/play/p/NcMTqPu75fe

And I get:

2009-11-10 23:00:00 +0000 UTC m=+0.000000001
2009-11-10T23:00:00Z

Which could be considered a breaking change. WDYT?

cc/ @duglin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the breaking change. I'm more bothered that:
1 - it wasn't spec compliant before and no one noticed
2 - not a single testcase needed to be changed

I agree with splitting the upgrade stuff into a separate PR. But can we also get at least one testcase added that checks the format of the time attribute and that it adheres to the CE spec (RFC3339) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get to work on it! Thank you so much for the feedback!

Copy link
Author

@MaryamTaj MaryamTaj Feb 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up the PR. Currently working on test cases:)

@MaryamTaj MaryamTaj force-pushed the issue-987 branch 2 times, most recently from a209c30 to 232dcc4 Compare February 24, 2024 23:56
Signed-off-by: MaryamTaj <tajm48822@gmail.com>
Signed-off-by: MaryamTaj <tajm48822@gmail.com>
Signed-off-by: MaryamTaj <tajm48822@gmail.com>
@embano1 embano1 marked this pull request as draft March 22, 2024 08:02
@embano1
Copy link
Member

embano1 commented Mar 22, 2024

@MaryamTaj converted to draft, seems you're still working on this. Once ready for review, please just mark as "Ready for review" and ping us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly marshal event time to RFC-3339 format
3 participants