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

Asyncapi date-time vs RFC3339 formats #233

Open
TheSadlig opened this issue Jun 17, 2024 · 1 comment
Open

Asyncapi date-time vs RFC3339 formats #233

TheSadlig opened this issue Jun 17, 2024 · 1 comment

Comments

@TheSadlig
Copy link
Contributor

Allo !

Currently, when a field has "date-time" as its format, it is parsed using time.RFC3339 (it is used in multiple places):

t, err := time.Parse(time.RFC3339, string(bMsg.Payload))

That constant is defined here:
https://pkg.go.dev/time#pkg-constants
as RFC3339 = "2006-01-02T15:04:05Z07:00"

According to the specification, the date-time format
https://www.asyncapi.com/docs/reference/specification/v3.0.0#dataTypeFormat
-> https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6

is defined as:

   time-secfrac    = "." 1*DIGIT
   time-numoffset  = ("+" / "-") time-hour ":" time-minute
   time-offset     = "Z" / time-numoffset

   partial-time    = time-hour ":" time-minute ":" time-second
                     [time-secfrac]
   full-date       = date-fullyear "-" date-month "-" date-mday
   full-time       = partial-time time-offset

   date-time       = full-date "T" full-time

The difference is with the time-secfrac which is not included in that constant.

I see two options to solve that:

  • Use time.RFC3339Nano which is defined as RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
    • Weirdly, it accepts more that one digit, which does not seem to be RFC3339-compliant.
    • I am unsure as to whether this could cause any issue
  • Redefine the constant as RFC3339 = "2006-01-02T15:04:05.9Z07:00" within generated code to ensure compliance

Please let me know what are your thoughts on this

Thanks,
TheSadlig

@lerenn
Copy link
Owner

lerenn commented Jun 18, 2024

I would go for the simplest one, so RFC3339Nano one, and add a test to ensure that it is correctly parsed in case that there is a breaking change in the future.

However, I'm not against the second solution :)

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

No branches or pull requests

2 participants