uutils / findutils

Rust implementation of findutils
MIT License
287 stars 35 forks source link

Implement `-newerXY` #307

Closed sylvestre closed 3 months ago

sylvestre commented 6 months ago

The upstream manpage states:

-newerXY reference
          Compares the timestamp of the current file with reference.   The
          reference  argument  is  normally the name of a file (and one of
          its timestamps is used for the comparison) but it may also be  a
          string  describing  an  absolute time.  X and Y are placeholders
          for other letters, and these letters select which time belonging
          to how reference is used for the comparison.

          a   The access time of the file reference
          B   The birth time of the file reference
          c   The inode status change time of reference
          m   The modification time of the file reference
          t   reference is interpreted directly as a time
$ find . ! -newermt 'jan 01, 2000' -exec touch -d@1706517278 {} +   
Error: Unrecognized flag: '-newermt'
hanbings commented 4 months ago

hi, this issue looks like there hasn't been an update here for a long time, can I give it a try?

cakebaker commented 4 months ago

@hanbings sure, go ahead :)

hanbings commented 4 months ago

Thanks.

Now find . ! -newermt 'jan 01, 2000' -exec touch -d@1706517278 {} + works, and -newerat and -newerct is also available. -newerBt is available, but depends on whether the file system supports birthed time / created time.

Use the following command to better observe the results.

find . -newermt 'jan 01, 2000'
find . -newermt 'jan 01, 2000 00:00:00'

In order to parse this time string, I added a function parse_date_str_to_timestamps() that converts from string to timestamp, then created the corresponding Matcher and compared it with the timestamp of the target file to get the result. I will add relevant test code later.

Please forgive my code for not looking very good.