parse_date

Function parse_date 

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

Strictly parse a calendar date in YYYY-MM-DD format.

§Behavior

  • Trims surrounding whitespace.
  • Requires zero-padded year-month-day (e.g., 2025-09-02).
  • Rejects datetime strings (e.g., 2025-09-02 12:34:56) and other formats.
  • Validates real calendar dates (e.g., leap years).

§Arguments

  • s: The input string (typically from CLI).

§Returns

  • Ok(Date) on success.
  • Err(String) with a short, user-friendly message otherwise (good for CLI).

§Examples

use linkleaf_core::validation::parse_date;
let d = parse_date("2025-01-03").unwrap();
assert_eq!(d.to_string(), "2025-01-03");
use linkleaf_core::validation::parse_date;
assert!(parse_date("2025/01/03").is_err());
assert!(parse_date("2025-1-3").is_err()); // not zero-padded