Merge pull request #1494 from nabellows/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add support for @%s time format
authored by Thayne McCombs · committed by GitHub · parents bc67826, ffde94c · Browse files · 3 files·+44 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+44 added−5 removed
- other:+44 added−5 removed
Provenance
- Commit
85cbea8- Tree
96d186d- Author
Thayne McCombs <astrothayne@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
bc67826- Parent 2
ffde94c
3 files changed+44 added−5 removed
modified:doc/fd.1+8 added-4 removed
310 unmodified lines311 .BI "\-\-changed-within " date|duration312 Filter results based on the file modification time.313 Files with modification times greater than the argument will be returned.314 The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point315-in time in either full RFC3339 format with time zone, or as a date or datetime in the316-local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).315+in time as full RFC3339 format with time zone, as a date or datetime in the316+local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR), or as the prefix '@'317+followed by the number of seconds since the Unix epoch (@[0-9]+).318 \fB\-\-change-newer-than\fR,319 .B --newer320 or321 .B --changed-after2 unmodified lines324 Examples:325 \-\-changed-within 2weeks326 \-\-change-newer-than "2018-10-27 10:00:00"327 \-\-newer 2018-10-27328+ \-\-changed-after @1704067200329 .TP330 .BI "\-\-changed-before " date|duration331 Filter results based on the file modification time.332 Files with modification times less than the argument will be returned.333 The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point332-in time in either full RFC3339 format with time zone, or as a date or datetime in the333-local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).334+in time as full RFC3339 format with time zone, as a date or datetime in the335+local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR), or as the prefix '@'336+followed by the number of seconds since the Unix epoch (@[0-9]+).337 .B --change-older-than338 or339 .B --older340 can be used as aliases.341 342 Examples:343 \-\-changed-before "2018-10-27 10:00:00"344 \-\-change-older-than 2weeks345+ \-\-older @1704067200346 .TP347 .BI "-o, \-\-owner " [user][:group]348 Filter files by their user and/or group. Format: [(user|uid)][:(group|gid)]. Either side349 is optional. Precede either side with a '!' to exclude files instead.164 unmodified linesmodified:src/filter/time.rs+35 added-1 removed
1-use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};1+use chrono::{DateTime, Local, NaiveDate, NaiveDateTime, Utc};2 3 use std::time::SystemTime;4 5 /// Filter based on time ranges.24 unmodified lines30 .ok()?31 .and_local_timezone(Local)32 .latest()33 })34+ .or_else(|| {35+ let timestamp_secs = s.strip_prefix('@')?.parse().ok()?;36+ NaiveDateTime::from_timestamp_opt(timestamp_secs, 0)?37+ .and_local_timezone(Utc)38+ .latest()39+ .map(Into::into)40+ })41 .map(|dt| dt.into())42 })43 }44 96 unmodified lines141 .applies_to(&ref_time));142 assert!(!TimeFilter::after(&ref_time, t10s_before)143 .unwrap()144 .applies_to(&t1m_ago));145+146+ let ref_timestamp = 1707723412u64; // Mon Feb 12 07:36:52 UTC 2024147+ let ref_time = DateTime::parse_from_rfc3339("2024-02-12T07:36:52+00:00")148+ .unwrap()149+ .into();150+ let t1m_ago = ref_time - Duration::from_secs(60);151+ let t1s_later = ref_time + Duration::from_secs(1);152+ // Timestamp only supported via '@' prefix153+ assert!(TimeFilter::before(&ref_time, &ref_timestamp.to_string()).is_none());154+ assert!(155+ TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))156+ .unwrap()157+ .applies_to(&t1m_ago)158+ );159+ assert!(160+ !TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))161+ .unwrap()162+ .applies_to(&t1s_later)163+ );164+ assert!(165+ !TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))166+ .unwrap()167+ .applies_to(&t1m_ago)168+ );169+ assert!(TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))170+ .unwrap()171+ .applies_to(&t1s_later));172 }173 }modified:CHANGELOG.md+1 added
1 unmodified line2 3 ## Features4 5 - Add `dir` as an alias to `directory` when using `-t` \ `--type`, see #1460 and #1464 (@Ato2207).6+- Add support for @%s date format in time filters similar to GNU date (seconds since Unix epoch for --older/--newer), see #1493 (@nabellows)7 8 ## Bugfixes9 10 - Respect NO_COLOR environment variable with `--list-details` option. (#1455)740 unmodified lines