Skip to content

Commit

Permalink
pkg/utils: Add function creating human-readable duration strings
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryMichal committed Jul 24, 2020
1 parent 47fe8cd commit 583a82d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 583a82d

Please sign in to comment.