Skip to content
Myr

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

3 files+44 added−5 removed

modified:doc/fd.1+8 added-4 removed
310 unmodified lines
311.BI "\-\-changed-within " date|duration312Filter results based on the file modification time.313Files with modification times greater than the argument will be returned.314The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point315in time in either full RFC3339 format with time zone, or as a date or datetime in the316local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).315in time as full RFC3339 format with time zone, as a date or datetime in the316local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR), or as the prefix '@'317followed by the number of seconds since the Unix epoch (@[0-9]+).318\fB\-\-change-newer-than\fR,319.B --newer320or321.B --changed-after
2 unmodified lines
324Examples: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|duration331Filter results based on the file modification time.332Files with modification times less than the argument will be returned.333The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point332in time in either full RFC3339 format with time zone, or as a date or datetime in the333local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).334in time as full RFC3339 format with time zone, as a date or datetime in the335local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR), or as the prefix '@'336followed by the number of seconds since the Unix epoch (@[0-9]+).337.B --change-older-than338or339.B --older340can be used as aliases.341342Examples:343 \-\-changed-before "2018-10-27 10:00:00"344 \-\-change-older-than 2weeks345 \-\-older @1704067200346.TP347.BI "-o, \-\-owner " [user][:group]348Filter files by their user and/or group. Format: [(user|uid)][:(group|gid)]. Either side349is optional. Precede either side with a '!' to exclude files instead.
164 unmodified lines
modified:src/filter/time.rs+35 added-1 removed
1use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};1use chrono::{DateTime, Local, NaiveDate, NaiveDateTime, Utc};23use std::time::SystemTime;45/// Filter based on time ranges.
24 unmodified lines
30 .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 lines
141 .applies_to(&ref_time));142 assert!(!TimeFilter::after(&ref_time, t10s_before)143 .unwrap()144 .applies_to(&t1m_ago));145146 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 line
23## Features45- 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)78## Bugfixes910- Respect NO_COLOR environment variable with `--list-details` option. (#1455)
740 unmodified lines