Parse the ISO 8601 signed extended-year form (`±YYYY[Y...]-MM-DD`) into raw `(year, month, day)` components, without validating the calendar date. The caller must have already verified that `string` begins with `+` or `-`; the year must have at least 4 digits. Returns `None` if the shape is malformed or any component fails to parse numerically.
(string: &str)
| 592 | /// the year must have at least 4 digits. Returns `None` if the shape is |
| 593 | /// malformed or any component fails to parse numerically. |
| 594 | fn parse_extended_ymd(string: &str) -> Option<(i32, u32, u32)> { |
| 595 | debug_assert!(string.starts_with('+') || string.starts_with('-')); |
| 596 | // Skip the sign and look for the hyphen that terminates the year digits. |
| 597 | // Per ISO 8601 the unsigned year part must be at least 4 digits. |
| 598 | let rest = &string[1..]; |
| 599 | let hyphen = rest.find('-')?; |
| 600 | if hyphen < 4 { |
| 601 | return None; |
| 602 | } |
| 603 | // The year substring is the sign and the digits (but not the separator), |
| 604 | // e.g. for "+10999-12-31", hyphen is 5 and s[..6] is "+10999". |
| 605 | let year: i32 = string[..hyphen + 1].parse().ok()?; |
| 606 | // The remainder should begin with a '-' which we strip off, leaving the month-day part. |
| 607 | let remainder = string[hyphen + 1..].strip_prefix('-')?; |
| 608 | let mut parts = remainder.splitn(2, '-'); |
| 609 | let month: u32 = parts.next()?.parse().ok()?; |
| 610 | let day: u32 = parts.next()?.parse().ok()?; |
| 611 | Some((year, month, day)) |
| 612 | } |
| 613 | |
| 614 | fn parse_date(string: &str) -> Option<NaiveDate> { |
| 615 | // If the date has an extended (signed) year such as "+10999-12-31" or "-0012-05-06" |
no test coverage detected