diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go index 6d38b709f..634d981e8 100644 --- a/src/pkg/utils/utils.go +++ b/src/pkg/utils/utils.go @@ -28,9 +28,11 @@ import ( "strconv" "strings" "syscall" + "time" "github.com/acobaugh/osrelease" "github.com/containers/toolbox/pkg/shell" + "github.com/docker/go-units" "github.com/godbus/dbus/v5" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" @@ -333,6 +335,14 @@ func GetMountOptions(target string) (string, error) { return mountOptions, nil } +// HumanDuration accepts a Unix time value and converts it into a human readable +// string. +// +// Examples: "5 minutes ago", "2 hours ago", "3 days ago" +func HumanDuration(duration int64) string { + return units.HumanDuration(time.Since(time.Unix(duration, 0))) + " ago" +} + // ImageReferenceCanBeID checks if 'image' might be the ID of an image func ImageReferenceCanBeID(image string) (bool, error) { matched, err := regexp.MatchString("^[a-f0-9]\\{6,64\\}$", image)