diff --git a/connector/docker.go b/connector/docker.go index ff0be28..7e6891c 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -7,6 +7,7 @@ import ( "time" "github.com/op/go-logging" + "github.com/hako/durafmt" "github.com/bcicen/ctop/connector/collector" "github.com/bcicen/ctop/connector/manager" @@ -187,7 +188,7 @@ func (cm *Docker) refresh(c *container.Container) { if webPort != "" { c.SetMeta("Web Port", webPort) } - c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006")) + c.SetMeta("created", insp.Created.Format("Mon Jan 02 15:04:05 2006")) c.SetMeta("uptime", calcUptime(insp)) c.SetMeta("health", insp.State.Health.Status) c.SetMeta("[ENV-VAR]", strings.Join(insp.Config.Env, ";")) @@ -209,11 +210,11 @@ func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bo func calcUptime(insp *api.Container) string { endTime := insp.State.FinishedAt - if endTime.IsZero() { + if endTime.IsZero() || insp.State.Running { endTime = time.Now() } uptime := endTime.Sub(insp.State.StartedAt) - return uptime.Truncate(time.Second).String() + return durafmt.Parse(uptime).LimitFirstN(1).String() } // Mark all container IDs for refresh diff --git a/go.mod b/go.mod index db92b25..0d036bf 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ require ( github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd github.com/fsouza/go-dockerclient v1.7.0 github.com/gizak/termui v2.3.1-0.20180817033724-8d4faad06196+incompatible + github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b // indirect github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c github.com/mattn/go-runewidth v0.0.2 github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d diff --git a/go.sum b/go.sum index c3c4806..ca3a07c 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4= +github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=