Skip to content
Snippets Groups Projects
date.rs 370 B
Newer Older
Stephen D's avatar
Stephen D committed
use anyhow::Context;
use chrono::NaiveDate;
Stephen D's avatar
Stephen D committed

// very basic org mode date parser
pub fn parse_org_date(s: &str) -> anyhow::Result<NaiveDate> {
Stephen D's avatar
Stephen D committed
    let s = s.strip_prefix('<').context("Invalid date")?;
    let s = s.strip_suffix('>').context("Invalid date")?;
    let s = s.rsplit_once(' ').context("Invalid date")?.0;

    Ok(NaiveDate::parse_from_str(s, "%Y-%m-%d")?)
Stephen D's avatar
Stephen D committed
}