pub fn is_ts_older_than(date: &str, older_than: &Duration) -> bool {
    let mut millis: Option<i64> = None;
    let try_formats = [
        DtFormat::UnixTimestamp,
        DtFormat::RFC2822,
        DtFormat::RFC3339,
        DtFormat::FromDtStr("%+"),
        DtFormat::FromNdtStr("%Y-%m-%d %H:%M:%S GMT"),
    ]
    .iter();

    for try_format in try_formats {
        if millis.is_some() {
            break;
        }
        match try_format {
            &DtFormat::UnixTimestamp => {
                if let Ok(dt) = date.parse::<i64>() {
                    millis = Some(dt);
                }
            }
            &DtFormat::RFC2822 => {
                if let Ok(dt) = DateTime::parse_from_rfc2822(date) {
                    millis = Some(dt.timestamp_millis());
                }
            }
            &DtFormat::RFC3339 => {
                if let Ok(dt) = DateTime::parse_from_rfc3339(date) {
                    millis = Some(dt.timestamp_millis());
                }
            }
            &DtFormat::FromDtStr(ref fmt) => {
                if let Ok(dt) = DateTime::parse_from_str(date, fmt) {
                    millis = Some(dt.timestamp_millis());
                }
            }
            &DtFormat::FromNdtStr(ref fmt) => {
                if let Ok(dt) = NaiveDateTime::parse_from_str(date, fmt) {
                    millis = Some(dt.timestamp_millis());
                }
            }
        }
    }

    let start = Utc::now().timestamp_millis() - older_than.as_millis() as i64;

    if start > millis.unwrap_or(Utc::now().timestamp_millis()) {
        true
    } else {
        false
    }
}
/// Compares a given date to a specified duration to check if the date is older
Compares a given date to a specified duration to check if the date is older
Compares a given date to a specified duration to check if the date is older
pub fn is_ts_older_than(date: &str, older_than: &Duration) -> bool {
    let mut millis: Option<i64> = None;
    let try_formats = [
        DtFormat::UnixTimestamp,
        DtFormat::RFC2822,
        DtFormat::RFC3339,
        DtFormat::FromDtStr("%+"),
        DtFormat::FromNdtStr("%Y-%m-%d %H:%M:%S GMT"),
    ]
    .iter();
    for try_format in try_formats {
        if millis.is_some() {
            break;
        }
        match try_format {
            &DtFormat::UnixTimestamp => {
                if let Ok(dt) = date.parse::<i64>() {
                    millis = Some(dt);
                }
            }
            &DtFormat::RFC2822 => {
                if let Ok(dt) = DateTime::parse_from_rfc2822(date) {
                    millis = Some(dt.timestamp_millis());
                }
            }
            &DtFormat::RFC3339 => {
                if let Ok(dt) = DateTime::parse_from_rfc3339(date) {
                    millis = Some(dt.timestamp_millis());
                }
            }
            &DtFormat::FromDtStr(ref fmt) => {
                if let Ok(dt) = DateTime::parse_from_str(date, fmt) {
                    millis = Some(dt.timestamp_millis());
                }
            }
            &DtFormat::FromNdtStr(ref fmt) => {
                if let Ok(dt) = NaiveDateTime::parse_from_str(date, fmt) {
                    millis = Some(dt.timestamp_millis());
                }
            }
        }
    }
    let start = Utc::now().timestamp_millis() - older_than.as_millis() as i64;
    if start > millis.unwrap_or(Utc::now().timestamp_millis()) {
        true
    } else {
        false
    }
}
pub fn is_ts_older_than ( date : & str , older_than : & Duration ) -> bool { let mut millis : Option < i64 > = None ; let try_formats = [ DtFormat :: UnixTimestamp , DtFormat :: RFC2822 , DtFormat :: RFC3339 , DtFormat :: FromDtStr ( " " ) , DtFormat :: FromNdtStr ( " " ) , ] . iter ( ) ; for try_format in try_formats { if millis . is_some ( ) { break ; } match try_format { & DtFormat :: UnixTimestamp => { if let Ok ( dt ) = date . parse :: < i64 > ( ) { millis = Some ( dt ) ; } } & DtFormat :: RFC2822 => { if let Ok ( dt ) = DateTime :: parse_from_rfc2822 ( date ) { millis = Some ( dt . timestamp_millis ( ) ) ; } } & DtFormat :: RFC3339 => { if let Ok ( dt ) = DateTime :: parse_from_rfc3339 ( date ) { millis = Some ( dt . timestamp_millis ( ) ) ; } } & DtFormat :: FromDtStr ( ref fmt ) => { if let Ok ( dt ) = DateTime :: parse_from_str ( date , fmt ) { millis = Some ( dt . timestamp_millis ( ) ) ; } } & DtFormat :: FromNdtStr ( ref fmt ) => { if let Ok ( dt ) = NaiveDateTime :: parse_from_str ( date , fmt ) { millis = Some ( dt . timestamp_millis ( ) ) ; } } } } let start = Utc :: now ( ) . timestamp_millis ( ) - older_than . as_millis ( ) as i64 ; if start > millis . unwrap_or ( Utc :: now ( ) . timestamp_millis ( ) ) { true } else { false } }
Compares a given date to a specified duration to check if the date is older
Compares a given date to a specified duration to check if the date is older
date
&str
older_than
&Duration