Function parse_date

Source
pub fn parse_date(
    s: &str,
    lenient_trailing_chars: bool,
) -> Result<Date, DateTimeParseError>
Expand description

Parse an HL7 date in the format: YYYY[MM[DD]

§Arguments

  • s - The string to parse
  • lenient_trailing_chars - If true, allow trailing characters after the date, otherwise throw an error

§Example

use hl7_parser::datetime::{parse_date, Date};

let date: Date = parse_date("20230312", false).expect("can parse date");

assert_eq!(date.year, 2023);
assert_eq!(date.month, Some(3));
assert_eq!(date.day, Some(12));