-
Notifications
You must be signed in to change notification settings - Fork 36
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
Support parsing ISO 8601 date time with offset in circe decoder #525
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gheine, any reason why you did not decide to go with OffsetDateTime
that you mentioned #520. I think it's actually better suited (as more direct) to what we're trying to achieve here. Example:
scala> ZonedDateTime.parse("2016-08-22T14:30+02:00[Europe/Paris]")
res5: java.time.ZonedDateTime = 2016-08-22T14:30+02:00[Europe/Paris]
scala> OffsetDateTime.parse("2016-08-22T14:30+02:00[Europe/Paris]")
java.time.format.DateTimeParseException: Text '2016-08-22T14:30+02:00[Europe/Paris]' could not be parsed, unparsed text found at index 22
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.OffsetDateTime.parse(OffsetDateTime.java:402)
at java.time.OffsetDateTime.parse(OffsetDateTime.java:387)
... 28 elided
As currently suggested, 2016-08-22T14:30+02:00[Europe/Paris]
would also be supported, while it does not seem to be a valid ISO 8601 date time (as per https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators).
Also, while this approach will address the (more severe) issue of parsing (huge improvement), still, the ability to output (encode) time as ISO 8601 will be missing (as flatten to UTC -- so time zone info gets lost).
My thought was that the scala/java data type for fields models and operation parameters for the apibuilder date_time type should/could be And correct, this fix only addresses the issue of parsing any ISO 8601 date time string, not the problem that timezone offset information is lost by converting to Instant. But since that would be a breaking change (code that relies on generated code that uses Instant would break if the spec is regenerated with OffsetDateTime). I'm working on a fix that will use a generator attribute to make that switch explicit. |
@gheine nice! I did refer to just a fact of using |
Even though hypothetical, I don't think there's harm in parsing beyond what the ISO 8601 spec mandates. |
Still, if the plan is to represent date time as |
We're not "introducing" |
@gheine by using Now I played with it some more, and it looks like
and also
Given the above, I don't see a reason to widen the accepted values outside of strict iso-8601 date time. (Just for the record: at the same time I am ok with the currently suggested changes but my preference would be to be more strict as stick to |
My proposal was to offer the choice between ZonedDateTime and Instant on the API level (ie. model case classes, client operations etc.) but in either case use ZonedDateTime to parse incoming json strings and then convert this to the appropriate API type (ZonedDateTime or Instant). So really the fact that we're using ZonedDateTime under the hood would just be an implementation detail. It might as well be "MyGreatDateTimeParser" that spits out the input String as either an Instant or a ZonedDateTime. But I see your point, the joda doesn't support zone id suffixes like |
@gheine regarding
I would be against allowing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃
@mkows Instant is the type that is being generated right now, so we can't remove it or change it without p*ssing people off. |
No description provided.