use std::path::Path;

pub fn display(p: &Path) -> String {
    p.display().to_string()
}

pub fn is_iso_date(s: &str) -> bool {
    s.len() == 10
        && s.as_bytes()[4] == b'-'
        && s.as_bytes()[7] == b'-'
        && s[..4].chars().all(|c| c.is_ascii_digit())
        && s[5..7].chars().all(|c| c.is_ascii_digit())
        && s[8..10].chars().all(|c| c.is_ascii_digit())
}

pub fn today_iso_date() -> Option<String> {
    let out = std::process::Command::new("date")
        .args(["-u", "+%Y-%m-%d"])
        .output()
        .ok()?;
    if !out.status.success() {
        return None;
    }
    let s = String::from_utf8_lossy(&out.stdout).trim().to_string();
    is_iso_date(&s).then_some(s)
}

pub fn current_dir() -> std::path::PathBuf {
    std::env::current_dir().expect("cwd readable")
}
