chronotope / chrono

Date and time library for Rust
Other
3.35k stars 536 forks source link

DateTime::parse_from_rfc3339 cannot parse BC dates #1631

Closed victorteokw closed 5 days ago

victorteokw commented 5 days ago

Thanks for this great crate!

I parse BC date with parse_from_rfc3339, which errors:

DateTime::parse_from_rfc3339("-0001-11-21T14:08:00.591Z")

How to correctly parse date BC?

Thanks

djc commented 5 days ago

RFC 3339 doesn't support negative years.

https://www.rfc-editor.org/rfc/rfc3339#section-5.6

victorteokw commented 4 days ago

Hi @djc, could ISO8601 be supported?

djc commented 2 days ago

You can use parse_from_str() to specify the format you expect. See also the docs:

Why isn’t this named parse_from_iso8601? That’s because ISO 8601 allows representing values in a wide range of formats, only some of which represent actual date-and-time instances (rather than periods, ranges, dates, or times). Some valid ISO 8601 values are also simultaneously valid RFC 3339 values, but not all RFC 3339 values are valid ISO 8601 values (or the other way around).