Closed NaviHX closed 1 month ago
I have a workaround here:
https://github.com/uutils/findutils/compare/dce8b2dd...fcb8da254
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 local_midnight = local_time.date().and_hms(0, 0, 0);
+ let local_midnight_seconds = local_midnight.timestamp();
+
+ UNIX_EPOCH + Duration::from_secs(local_midnight_seconds as u64)
} else {
matcher_io.now()
}
please submit a PR :)
When using the
-daystart
option with the find command, today's midnight is incorrect for users whose local time zone differs from UTC. Specifically, instead of considering the local time zone, the implementation calculates midnight by using the following code:This code causes the calculated
midnight_seconds
is always based on UNIX_EPOCH (00:00 +0000). However, UNIX_EPOCH is not midnight in other time zones. For example, runfind -mtime 0
atWed, 16 Oct 2024 14:27:57 +0800
and the above code will output: