Function human_date_parser::from_human_time
source · pub fn from_human_time(str: &str) -> Result<DateTime<Local>, ParseError>Expand description
Converts a human expression of a date into a more usable one.
Errors
This function will return an error if the string contains values than can not be parsed into a date.
Examples
use human_date_parser::from_human_time;
fn main() {
let date = from_human_time("Last Friday at 19:45").unwrap();
println!("{date}");
}Examples found in repository?
examples/stdin.rs (line 12)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut buffer = String::new();
let stdin = stdin();
loop {
buffer.clear();
stdin.read_line(&mut buffer).unwrap();
let time = match human_date_parser::from_human_time(&buffer) {
Ok(time) => time,
Err(e) => {
println!("{e}");
continue;
}
};
let now = Local::now();
println!("Time now: {now}");
println!("Calculated: {time}\n");
}
}