You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-daystart option does not calculate midnight with local time zone #466
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, run find -mtime 0 at Wed, 16 Oct 2024 14:27:57 +0800 and the above code will output:
Midnight seconds: 1729036800
# > date -d "@1729036800" -R# Wed, 16 Oct 2024 08:00:00 +0800
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()
}
Activity
NaviHX commentedon Oct 17, 2024
I have a workaround here:
dce8b2d...fcb8da2
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() }sylvestre commentedon Oct 17, 2024
please submit a PR :)