diff --git a/Cargo.lock b/Cargo.lock index 7a8fde1..c2a267d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,9 +139,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.28" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", diff --git a/Cargo.toml b/Cargo.toml index 70b49e0..f4d856f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ version = "4.4.6" features = ["suggestions", "color", "wrap_help", "cargo", "derive"] [dependencies.chrono] -version = "0.4.28" +version = "0.4.31" default-features = false features = ["std", "clock"] diff --git a/src/filter/time.rs b/src/filter/time.rs index 869fd42..0070e5e 100644 --- a/src/filter/time.rs +++ b/src/filter/time.rs @@ -1,4 +1,4 @@ -use chrono::{offset::TimeZone, DateTime, Local, NaiveDate}; +use chrono::{DateTime, Local, NaiveDate, NaiveDateTime}; use std::time::SystemTime; @@ -20,11 +20,17 @@ impl TimeFilter { .ok() .or_else(|| { NaiveDate::parse_from_str(s, "%F") - .ok() - .and_then(|nd| nd.and_hms_opt(0, 0, 0)) - .and_then(|ndt| Local.from_local_datetime(&ndt).single()) + .ok()? + .and_hms_opt(0, 0, 0)? + .and_local_timezone(Local) + .latest() + }) + .or_else(|| { + NaiveDateTime::parse_from_str(s, "%F %T") + .ok()? + .and_local_timezone(Local) + .latest() }) - .or_else(|| Local.datetime_from_str(s, "%F %T").ok()) .map(|dt| dt.into()) }) } @@ -52,8 +58,10 @@ mod tests { #[test] fn is_time_filter_applicable() { - let ref_time = Local - .datetime_from_str("2010-10-10 10:10:10", "%F %T") + let ref_time = NaiveDateTime::parse_from_str("2010-10-10 10:10:10", "%F %T") + .unwrap() + .and_local_timezone(Local) + .latest() .unwrap() .into();