stdin/
stdin.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::io::stdin;

use chrono::Local;
use human_date_parser::ParseResult;

fn main() {
    let mut buffer = String::new();
    let stdin = stdin();

    println!("Describe a date or time:");
    loop {
        buffer.clear();
        stdin.read_line(&mut buffer).unwrap();
        let result = match human_date_parser::from_human_time(&buffer) {
            Ok(time) => time,
            Err(e) => {
                println!("{e}");
                continue;
            }
        };

        let now = Local::now();

        match result {
            ParseResult::DateTime(datetime) => {
                println!("Time now: {now}");
                println!("Time then: {datetime}\n");
            }
            ParseResult::Date(date) => println!("Date: {date}\n"),
            ParseResult::Time(time) => println!("Time: {time}\n"),
        };
    }
}