MCPcopy Create free account
hub / github.com/apache/arrow-rs / parse_extended_ymd

Function parse_extended_ymd

arrow-cast/src/parse.rs:594–612  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

592/// the year must have at least 4 digits. Returns `None` if the shape is
593/// malformed or any component fails to parse numerically.
594fn 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
614fn parse_date(string: &str) -> Option<NaiveDate> {
615 // If the date has an extended (signed) year such as "+10999-12-31" or "-0012-05-06"

Callers 2

parse_dateFunction · 0.85
parse_date_to_daysFunction · 0.85

Calls 3

findMethod · 0.80
parseMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected