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?
@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.
See https://crystal-lang.org/api/master/Time.html#to_json%28json%3AJSON%3A%3ABuilder%29-instance-method and https://github.com/crystal-lang/crystal/pull/5123#discussion_r193022243
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.
Most helpful comment
Sure, but why are there seconds in the offset? Looking at RFC 3339 the offset is either
+00:00orZ. A+00:00:00offset is invalid.