Skip to content

Conversation

@zhxnlai
Copy link
Contributor

@zhxnlai zhxnlai commented Sep 29, 2020

According to the documentation, OffsetDateTime's toString method uses this format uuuu-MM-dd'T'HH:mmXXXXX when seconds is zero. This is incompatible with RFC3339 and cannot be parsed by other cloud events SDKs.

Here is an demo of the incompatibility:
https://play.golang.org/p/9db3zuJTM_k

@zhxnlai zhxnlai force-pushed the zl-200929-seralize-time-to-RFC3339-compliant-string branch from e0c73cc to dd9998f Compare September 29, 2020 16:33
@matejvasek
Copy link
Contributor

In general looks good, but it breaks some test since it adds unnecessary zeros to fraction part of date (2018-04-26T14:48:09.123400Z instead of 2018-04-26T14:48:09.1234Z).
Maybe:

    public static final DateTimeFormatter RFC3339_DATE_FORMAT = new DateTimeFormatterBuilder()	
        .appendPattern("yyyy-MM-dd'T'HH:mm:ss")	
        .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)	
        .appendOffsetId()	
        .toFormatter();

would work better than java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME

the above was used in previous version https://github.com/cloudevents/sdk-java/pull/216/files#diff-bac8dca098ba932b36f5b17870212371L34.

Or maybe we could change assertions in the test, I think that would be acceptable too.

/cc @slinkydeveloper

Signed-off-by: Zhixuan Lai <zhixuan@squareup.com>
@zhxnlai zhxnlai force-pushed the zl-200929-seralize-time-to-RFC3339-compliant-string branch from dd9998f to de5db6b Compare September 30, 2020 06:05
@zhxnlai
Copy link
Contributor Author

zhxnlai commented Sep 30, 2020

@matejvasek fixed the test. It looks like ISO_OFFSET_DATE_TIME actually removes unnecessary zeros in the test 😉

@slinkydeveloper
Copy link
Member

I personally don't care about the more zeroes, if that's compliant to the spec, fine. I would love to avoid adding custom formats

Copy link
Member

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

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

@matejvasek can you double check this one?

@matejvasek
Copy link
Contributor

@zhxnlai my bad, I mistaken expected with actual in the test output.

@matejvasek
Copy link
Contributor

LGTM

@matejvasek
Copy link
Contributor

Note: when reading input we allow missing seconds, but for input it's OK to be less strict as is doesn't affect compatibility.

@slinkydeveloper slinkydeveloper merged commit a09b03b into cloudevents:master Sep 30, 2020
@zhxnlai zhxnlai deleted the zl-200929-seralize-time-to-RFC3339-compliant-string branch October 6, 2020 03:39
@zhxnlai
Copy link
Contributor Author

zhxnlai commented Oct 6, 2020

@matejvasek @slinkydeveloper any chance we could roll this out soon?

@matejvasek
Copy link
Contributor

@zhxnlai I am not maintainer here (@slinkydeveloper is), but I would say probably not. This was merged just one day after releasing 2.0.0 Milestone 3, and there hasn't been much done for M4.

@zhxnlai
Copy link
Contributor Author

zhxnlai commented Oct 8, 2020

Technically this is a bug fix. My java application is stuck with milestone1 because it needs to interop with a go application that uses the go SDK. I am waiting for this fix to go out so that I can upgrade it to the latest Java SDK

@slinkydeveloper
Copy link
Member

@zhxnlai hopefully another release will be out soon, we're trying to solve this issue first #250 😄

@slinkydeveloper
Copy link
Member

@zhxnlai Meanwhile you can use the snapshot packages, which should include this fix

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.

3 participants