Crystal: Default serialization of Time in JSON not RFC2822 nor ISO8601 compliant

Created on 28 Feb 2019  路  7Comments  路  Source: crystal-lang/crystal

I'm playing with crystal and moment.js; when I serialize the date into a json, it returns this string:

{
  x: Time.now
}.to_json # => {"x": "2019-02-28T14:48:12+07:00:00"}

However, moment.js tell me the date format is invalid and should be RFC2822 compliant.

Basically, the seconds in the time zone stamp are not accepted. 2019-02-28T14:48:12+07:00 is accepted however.

I don't know if the time format outputted by crystal is RFC2822 compliant or not - if so, it could be a problem on moment.js library -; it seems any way overkill to have seconds in timezone, no?

Most helpful comment

Sure, but why are there seconds in the offset? Looking at RFC 3339 the offset is either +00:00 or Z. A +00:00:00 offset is invalid.

All 7 comments

@anykeyh => https://crystal-lang.org/api/master/Time.html#to_rfc2822%28io%3AIO%29-instance-method

All in all keep an eye over the API docs, they usually have the answers :)

Thank you, I reformulate my issue then :smile:

Why date serialized to JSON are not by default RFC2822 or ISO 8601 compliant?

EDIT: Title changed to reflect my issue.

Sure, but why are there seconds in the offset? Looking at RFC 3339 the offset is either +00:00 or Z. A +00:00:00 offset is invalid.

I think this is a mistake, might be a recent one. This wasn't always like that.

Yes, this was changed in #5123 and the new RFC_3339 formatter simply incorrectly outputs offset seconds which are not defined in RFC 3339 (they're however in ISO 8601).

RFC 2822 is an entirely different format.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

will picture will  路  3Comments

asterite picture asterite  路  3Comments

RX14 picture RX14  路  3Comments

lgphp picture lgphp  路  3Comments

pbrusco picture pbrusco  路  3Comments