Repository navigation
fs: accept multi-unit relative times like 1d12h in Time options - #10130
Conversation
The docs say Time options take the same relative forms as Duration options, with "1d12h" as an example, but ParseTime only tried time.ParseDuration and single-suffix values, so --max-age style Time options such as --s3-version-at 1d12h were rejected.
|
Thanks for spotting this. Rather than adding another step to the chain in Something like this: // Attempt to parse as a text time
t, err = parseTimeDates(date)
if err == nil {
return t, nil
}
// Attempt to parse as a duration offset from now
d, err := ParseDuration(date)
if err != nil {
return t, err
}
return now.Add(-d), nilPlease keep the Your new test cases pass with this change and so does the rest of |
Have ParseTime call ParseDuration directly instead of repeating its chain of duration parsers, so there is only one definition of a relative time and Time and Duration options can't drift apart again. parseTimeDates is still tried first so dates keep their timezone.
|
Thanks, that's much cleaner. I've pushed a commit that makes |
What does this change do?
The time options docs say
TimeandDurationoptions take the same relative forms, with"2h45m"and"1d12h"as examples. A relative value passed as aTimeis treated as an offset from now.ParseDurationaccepts multi-unit values throughparseDurationSequence, butParseTimeonly triestime.ParseDurationand the single-suffix parser. So any value that mixes rclone's own units (d,w,M,y) with others is rejected forTimeoptions, such as--s3-version-at,--b2-version-atand--http-no-head-time:--s3-version-at 36hworks, and1d12hworks forDurationoptions like--max-age.The fix makes
ParseTimealso tryparseDurationSequence, likeparseDurationFromNowalready does.Tests: I added
1d12hand1w2dtoTestParseTime. They fail before the change and pass after.go test ./fspasses andgo vet ./fsis clean.Linked issue
None. This is a small, obvious bug fix I found while reading the code.
Checklist
Prepared with AI assistance. I reviewed, built and tested the change myself.