diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-11 18:04:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 18:04:51 -0700 |
commit | 300b53cffea54724132028a2a7da5f6c77cd546c (patch) | |
tree | 71d3c99b3342c81a6d70a722879bd9a8a1f1d259 /pkg/util/utils.go | |
parent | dcd253f2e4da25e7e5af33bef4de5529162a7c1b (diff) | |
parent | ca1e76ff632dec0b0e00e25f26677887ca8cc625 (diff) | |
download | podman-300b53cffea54724132028a2a7da5f6c77cd546c.tar.gz podman-300b53cffea54724132028a2a7da5f6c77cd546c.tar.bz2 podman-300b53cffea54724132028a2a7da5f6c77cd546c.zip |
Merge pull request #2527 from baude/events
Add event logging to libpod, even display to podman
Diffstat (limited to 'pkg/util/utils.go')
-rw-r--r-- | pkg/util/utils.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go index a4576191b..d7e1ddd38 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -7,6 +7,7 @@ import ( "path/filepath" "strings" "syscall" + "time" "github.com/BurntSushi/toml" "github.com/containers/image/types" @@ -347,3 +348,25 @@ func StorageConfigFile() string { } return storage.DefaultConfigFile } + +// ParseInputTime takes the users input and to determine if it is valid and +// returns a time format and error. The input is compared to known time formats +// or a duration which implies no-duration +func ParseInputTime(inputTime string) (time.Time, error) { + timeFormats := []string{time.RFC3339Nano, time.RFC3339, "2006-01-02T15:04:05", "2006-01-02T15:04:05.999999999", + "2006-01-02Z07:00", "2006-01-02"} + // iterate the supported time formats + for _, tf := range timeFormats { + t, err := time.Parse(tf, inputTime) + if err == nil { + return t, nil + } + } + + // input might be a duration + duration, err := time.ParseDuration(inputTime) + if err != nil { + return time.Time{}, errors.Errorf("unable to interpret time value") + } + return time.Now().Add(-duration), nil +} |