chrono
chrono copied to clipboard
ISO 8601 parsers
My main motivation for adding an ISO 8601 parser is that chrono is currently unable to parse is own Debug output if the year is outside the 0..=9999 range supported by RFC 3339. Edit: I forgot the FromString implementation of DateTime is very forgiving and accepts this.
A second motivation is that this crate frequently mentions ISO 8601. Then it is strange it does not even have a parser for that format :laughing:.
ISO 8601 date/time strings have a pretty complex format. I see it as a combination of 12 different formats for the date, 12 formats for the time, and 4 for the offset.
I have made the parser public as a parse_from_iso8601 method on NaiveDate, NaiveTime, NaiveDateTime and DateTime::<FixedOffset>.
Sorry that this is such a large PR. The only thing I can say is that about half of it are tests and documentation.
Fixes https://github.com/chronotope/chrono/issues/587.
I wondered if I could use floats as they may not be supported by all targets, and the CI gives the answer: no. I'll figure something out with just integers.
@jtmoon79 Thank you for the review. Sorry I am a bit slow slow with addressing your comments. I'll probably fix it up this week.
Codecov Report
Merging #1143 (afa45c6) into 0.4.x (e730c6a) will increase coverage by
0.18%. The diff coverage is97.29%.
@@ Coverage Diff @@
## 0.4.x #1143 +/- ##
==========================================
+ Coverage 91.35% 91.53% +0.18%
==========================================
Files 38 39 +1
Lines 17034 17550 +516
==========================================
+ Hits 15562 16065 +503
- Misses 1472 1485 +13
| Files Changed | Coverage Δ | |
|---|---|---|
| src/format/mod.rs | 85.04% <ø> (ø) |
|
| src/format/parse_iso8601.rs | 95.67% <95.67%> (ø) |
|
| src/datetime/mod.rs | 86.96% <100.00%> (+0.87%) |
:arrow_up: |
| src/datetime/tests.rs | 96.59% <100.00%> (+0.09%) |
:arrow_up: |
| src/format/parse.rs | 97.30% <100.00%> (+0.06%) |
:arrow_up: |
| src/format/scan.rs | 99.26% <100.00%> (+0.01%) |
:arrow_up: |
| src/naive/date.rs | 96.35% <100.00%> (+0.05%) |
:arrow_up: |
| src/naive/datetime/mod.rs | 97.46% <100.00%> (+0.07%) |
:arrow_up: |
| src/naive/datetime/tests.rs | 98.71% <100.00%> (+0.08%) |
:arrow_up: |
| src/naive/time/mod.rs | 96.09% <100.00%> (+0.13%) |
:arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more