From 0906b3094d192427524dc8652de23f4e7acbcfd1 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 4 May 2018 15:39:44 -0400 Subject: Fix calculation of RunningFor in ps json output Signed-off-by: Matthew Heon Closes: #727 Approved by: rhatdan --- cmd/podman/ps.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cmd/podman') diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index 907c437b6..a0b6f134b 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -395,7 +395,7 @@ func getTemplateOutput(containers []*libpod.Container, opts batchcontainer.PsOpt runningFor := "" // If the container has not be started, the "zero" value of time is 0001-01-01 00:00:00 +0000 UTC // which would make the time elapsed about a few hundred of years. So checking for the "zero" value of time.Time - if batchInfo.StartedTime != (time.Time{}) { + if !batchInfo.StartedTime.IsZero() { runningFor = units.HumanDuration(time.Since(batchInfo.StartedTime)) } createdAt := batchInfo.ConConfig.CreatedTime.Format("2006-01-02 15:04:05 -0700 MST") @@ -495,7 +495,6 @@ func getJSONOutput(containers []*libpod.Container, opts batchcontainer.PsOptions ImageID: batchInfo.ConConfig.RootfsImageID, Command: batchInfo.ConConfig.Spec.Process.Args, CreatedAt: batchInfo.ConConfig.CreatedTime, - RunningFor: time.Since(batchInfo.ConConfig.CreatedTime), Status: batchInfo.ConState.String(), Ports: batchInfo.ConConfig.PortMappings, RootFsSize: batchInfo.RootFsSize, @@ -506,6 +505,11 @@ func getJSONOutput(containers []*libpod.Container, opts batchcontainer.PsOptions ContainerRunning: batchInfo.ConState == libpod.ContainerStateRunning, Namespaces: ns, } + + if !batchInfo.StartedTime.IsZero() { + params.RunningFor = time.Since(batchInfo.StartedTime) + } + psOutput = append(psOutput, params) } return psOutput, nil -- cgit v1.2.3-54-g00ecf