diff --git a/Cargo.lock b/Cargo.lock index 7fb74da..6a4d691 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,9 +250,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "filetime" @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libredox" @@ -421,9 +421,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.12" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -497,9 +497,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.20.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "onig" @@ -680,9 +680,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.4.1", "errno", @@ -783,9 +783,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", diff --git a/src/find/matchers/time.rs b/src/find/matchers/time.rs index 260219b..e7d07fb 100644 --- a/src/find/matchers/time.rs +++ b/src/find/matchers/time.rs @@ -9,6 +9,8 @@ use std::fs::{self, Metadata}; use std::io::{stderr, Write}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use chrono::{DateTime, Local, Timelike}; + #[cfg(unix)] use std::os::unix::fs::MetadataExt; @@ -19,10 +21,14 @@ const SECONDS_PER_DAY: i64 = 60 * 60 * 24; fn get_time(matcher_io: &mut MatcherIO, today_start: bool) -> SystemTime { if today_start { // the time at 00:00:00 of today - let duration = matcher_io.now().duration_since(UNIX_EPOCH).unwrap(); - let seconds = duration.as_secs(); - let midnight_seconds = seconds - (seconds % 86400); - UNIX_EPOCH + Duration::from_secs(midnight_seconds) + let duration_since_unix_epoch = matcher_io.now().duration_since(UNIX_EPOCH).unwrap(); + let seconds_since_unix_epoch = duration_since_unix_epoch.as_secs(); + let utc_time = DateTime::from_timestamp(seconds_since_unix_epoch as i64, 0).unwrap(); + let local_time = utc_time.with_timezone(&Local); + let seconds_since_last_midnight = local_time.num_seconds_from_midnight(); + let local_midnight_seconds = local_time.timestamp() - seconds_since_last_midnight as i64; + + UNIX_EPOCH + Duration::from_secs(local_midnight_seconds as u64) } else { matcher_io.now() } @@ -396,6 +402,7 @@ impl FileAgeRangeMatcher { #[cfg(test)] mod tests { + use chrono::NaiveTime; use std::fs; use std::fs::{File, OpenOptions}; use std::io::Read; @@ -616,6 +623,15 @@ mod tests { ); } + #[test] + fn get_local_midnight() { + let deps = FakeDependencies::new(); + let midnight = get_time(&mut deps.new_matcher_io(), true); + + let midnight = DateTime::::from(midnight); + assert_eq!(midnight.time(), NaiveTime::from_hms_opt(0, 0, 0).unwrap()) + } + #[test] fn file_time_matcher_modified_changed_accessed() { let temp_dir = Builder::new()