Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mc find - allow absolute times #5118

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/ls-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ var rewindSupportedFormat = []string{
"2006.01.02T15:04",
"2006.01.02T15:04:05",
time.RFC3339,
printDate,
}

// Parse rewind flag while considering the system local time zone
Expand Down
22 changes: 20 additions & 2 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,16 @@ func isOlder(ti time.Time, olderRef string) bool {
}
objectAge := time.Since(ti)
olderThan, e := ParseDuration(olderRef)
fatalIf(probe.NewError(e), "Unable to parse olderThan=`"+olderRef+"`.")
if e != nil {
for _, format := range rewindSupportedFormat {
if t, e2 := time.Parse(format, olderRef); e2 == nil {
olderThan = Duration(time.Since(t))
e = nil
break
}
}
}
fatalIf(probe.NewError(e), "Unable to parse olderThan=`"+olderRef+"`. Supply relative '7d6h2m' or absolute '"+printDate+"'.")
return objectAge < time.Duration(olderThan)
}

Expand All @@ -187,7 +196,16 @@ func isNewer(ti time.Time, newerRef string) bool {

objectAge := time.Since(ti)
newerThan, e := ParseDuration(newerRef)
fatalIf(probe.NewError(e), "Unable to parse newerThan=`"+newerRef+"`.")
if e != nil {
for _, format := range rewindSupportedFormat {
if t, e2 := time.Parse(format, newerRef); e2 == nil {
newerThan = Duration(time.Since(t))
e = nil
break
}
}
}
fatalIf(probe.NewError(e), "Unable to parse newerThan=`"+newerRef+"`. Supply relative '7d6h2m' or absolute '"+printDate+"'.")
return objectAge >= time.Duration(newerThan)
}

Expand Down
Loading