Comparing dates

I’m very new to Rust and I’m trying to figure out how to compare dates. I’m sure I’m just not understanding the data types and formats I’m working with.

I’m trying to find files whose modified date is greater than a given date.

Setting arbitrary start date:
let start = time::now_utc() + Duration::days(-180);

Then I get the modified time.
let metadata = match fs::metadata(path) {
Err(_why) => continue,
Ok(f) => f,};
let mtime = metadata.modified();

How do I see if mtime is greater than start? Any help and corrections appreciated and thanks.

Can you have a look at this

extern crate chrono;

use chrono::{Duration, Utc};
use std::path::Path;

fn mtime_greater<P: AsRef<Path>>(path: P) -> std::io::Result<bool> {
    let start = Utc::now() - Duration::days(180);
    Ok(std::fs::metadata(path)?.modified()? > start.into())

Thanks all, the mtime_greater fn helped a lot, understanding things a little better.

1 Like