fs: accept multi-unit relative times like 1d12h in Time options

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.
This commit is contained in:
kevin authored and GitHub committed 2026-10-31 12:24:46 +00:00
1 parent 989fd82b13
commit dee8b7e285
2 files changed
+7 -11

No files matched your search

+5 -11
View File
@@ -41,18 +41,12 @@ func ParseTime(date string) (t time.Time, err error) {
return t, nil
}
// Attempt to parse as a time.Duration offset from now
d, err := time.ParseDuration(date)
if err == nil {
return now.Add(-d), nil
// Attempt to parse as a duration offset from now
d, err := ParseDuration(date)
if err != nil {
return t, err
}
d, err = parseDurationSuffixes(date)
if err == nil {
return now.Add(-d), nil
}
return t, err
return now.Add(-d), nil
}
// Set a Time
+2
View File
@@ -50,6 +50,8 @@ func TestParseTime(t *testing.T) {
{"-1x", time.Time{}, true},
{"off", time.Time{}, false},
{"1h2m3s", now.Add(-(time.Hour + 2*time.Minute + 3*time.Second)), false},
{"1d12h", now.Add(-time.Hour * 36), false},
{"1w2d", now.Add(-time.Hour * 24 * 9), false},
{"2001-02-03", time.Date(2001, 2, 3, 0, 0, 0, 0, time.Local), false},
{"2001-02-03 10:11:12", time.Date(2001, 2, 3, 10, 11, 12, 0, time.Local), false},
{"2001-08-03 10:11:12", time.Date(2001, 8, 3, 10, 11, 12, 0, time.Local), false},