Skip to main content

parse_bounded

Function parse_bounded 

Source
pub fn parse_bounded(
    text: &str,
    first: MaterialDate,
    last: MaterialDate,
) -> Result<MaterialDate, DateInputError>
Expand description

Parse text as a compact date and check it against first..=last.

The bounds half of the reference’s _isValidAcceptableDate; a caller’s selectableDayPredicate is applied on top by DateInputField::parse, which owns the closure.

use frust_material::{DateInputError, MaterialDate, parse_bounded};

let first = MaterialDate::new(2026, 1, 1);
let last = MaterialDate::new(2026, 12, 31);
assert_eq!(parse_bounded("08/20/2026", first, last), Ok(MaterialDate::new(2026, 8, 20)));
assert_eq!(parse_bounded("08/20/2027", first, last), Err(DateInputError::OutOfRange));
assert_eq!(parse_bounded("nonsense", first, last), Err(DateInputError::Format));