Minor bug: --min-age can't be larger than --max-age

What is the problem you are having with rclone?

I'd like to copy files and filter them using the --min-age and --max-age flags together.

RClone produces the below error, even though my specified dates look like they are correct.

After reading the documentation carefully, it looks like I put the dates the wrong way around, but the error message is what confused me and led me to believe it was correct.

2024/01/10 09:38:56 filter: --min-age can't be larger than --max-age

Run the command 'rclone version' and share the full output of the command.

rclone-v1.65.1 version

rclone v1.65.1
- os/version: Microsoft Windows 10 Enterprise 21H2 (64 bit)
- os/kernel: 10.0.19044.3448 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.21.5
- go/linking: static
- go/tags: cmount

Which cloud storage system are you using? (eg Google Drive)

Seems to occur regardless of cloud storage system. I'm using Amazon S3.

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone-v1.65.1 copy remote1:path1 remote2:path2 --min-age 2024-01-01 --max-age 2024-01-11 -vv

Per above, min age is smaller than max age but the rclone log error message appears to say otherwise.

The rclone config contents with secrets removed.

Paste config here

A log from the command with the -vv flag

rclone-v1.65.1 copy remote1:path1 remote2:path2 --min-age 2024-01-01 --max-age 2024-01-11 -vv
2024/01/10 09:46:42 DEBUG : --min-age 1.3439192519117062w to 2024-01-01 00:00:00.0022475 +0200 SAST m=-812801.671461699
2024/01/10 09:46:42 filter: --min-age can't be larger than --max-age
Suggested fix

It is clearer now that --min-age must be AFTER --max-age, but in my opinion that means it must be LARGER. The error message says that min can't be larger than max.
Presumably this is because --min-age 2d and --max-age 4d would be correct and this is when max is "larger than" min - even though it means that min is AFTER max.

I suggest the error message is changed to reflect this:

filter: --min-age can't refer to a point in time before --max-age

The min age max age is quite confusing I agree.

You can think of min age as older and maybe I should have called the flag that! Perhaps we could make an alias...

Between them min age and max age define a time window with min age refering to the newer time and max age refering to the older time.

So I think your new text is correct, but it should probably include the old text too as that makes more sense if you supplied 2d instead of a date.

me too, from day one, until now, i am always a bit confused about --min-age and --max-age
somehow my small brain cannot grok it, i find myself checking the docs each time.

the overlords of zork fancy a PR!

Ha, ha, yes me too.

I don't think the library supports aliases but we could duplicate the flags something like

--- a/fs/filter/filterflags/filterflags.go
+++ b/fs/filter/filterflags/filterflags.go
@@ -56,6 +56,8 @@ func AddFlags(flagSet *pflag.FlagSet) {
 	flags.StringArrayVarP(flagSet, &Opt.FilesFromRaw, "files-from-raw", "", nil, "Read list of source-file names from file without any processing of lines (use - to read from stdin)", "Filter")
 	flags.FVarP(flagSet, &Opt.MinAge, "min-age", "", "Only transfer files older than this in s or suffix ms|s|m|h|d|w|M|y", "Filter")
 	flags.FVarP(flagSet, &Opt.MaxAge, "max-age", "", "Only transfer files younger than this in s or suffix ms|s|m|h|d|w|M|y", "Filter")
+	flags.FVarP(flagSet, &Opt.MinAge, "older", "", "Only transfer files older than this in s or suffix ms|s|m|h|d|w|M|y", "Filter")
+	flags.FVarP(flagSet, &Opt.MaxAge, "younger", "", "Only transfer files younger than this in s or suffix ms|s|m|h|d|w|M|y", "Filter")
 	flags.FVarP(flagSet, &Opt.MinSize, "min-size", "", "Only transfer files bigger than this in KiB or suffix B|K|M|G|T|P", "Filter")
 	flags.FVarP(flagSet, &Opt.MaxSize, "max-size", "", "Only transfer files smaller than this in KiB or suffix B|K|M|G|T|P", "Filter")
 	flags.BoolVarP(flagSet, &Opt.IgnoreCase, "ignore-case", "", false, "Ignore case in filters (case insensitive)", "Filter")

What about?

timestamp-before for min-age
timestamp-after for max-age

older and younger still make my brain to pause to think about their meaning:)

I guess it depends on whether you are suppling a duration or a timestamp

--min-age 1d
--older 1d

This reads to me "minimum age 1 day" or "older than 1 day" which make some sort of sense.

--min-age 2024-01-01
--older 2024-01-01

Where as "minimum age 2024-01-01" doesn't make a lot of sense, whereas "older than 2024-01-01" makes some sense though "timestamp before 2024-01-01" would make even more sense!

As both timestamp and duration are valid options for these flags I do not think there is 100% clear names wording... Though for me --timestamp-before and --timestamp-after are the closest to my brain logic:)

Maybe we just have to live with --min-age and --max-age + frequent looks at the docs:)

Thanks for all the feedback.

TBH I don't think a (significant) code change is needed, but more some clarity on how the existing parameters should be used in the docs and log message.

Suggestions:

1] Update docs for --min-age and --max-age , to make it more obvious what the correct values would be and that an error will occur if incorrect values are provided.

Suggested docs for --min-age
"
Note that if --max-age is also used then it must resolve to timestamp before --min-age.
Example 1: --max-age 5d --min-age 1d
Example 2: --max-age 2021-01-01 --min-age 2023-12-31
"

Suggested docs for --max-age
"
Note that if --min-age is also used then it must resolve to timestamp after --max-age.

Example 1: --max-age 5d --min-age 1d
Example 2: --max-age 2021-01-01 --min-age 2023-12-31
"

2] Update the filter error message as well

filter: --min-age must resolve to a timestamp after --max-age. Refer to the docs for examples.

What do you think?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.