From 0099677670e03b2e06b1f16e7c52465719692e74 Mon Sep 17 00:00:00 2001 From: frankyang Date: Wed, 31 Jul 2019 17:54:13 +0800 Subject: [PATCH] create time should in seconds instead of nano seconds Signed-off-by: frankyang --- apis/server/container_bridge.go | 2 +- cli/history.go | 2 +- cli/ps.go | 6 +++--- daemon/mgr/container_types.go | 4 ++-- pkg/utils/timeutils.go | 4 ++-- pkg/utils/timeutils_test.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apis/server/container_bridge.go b/apis/server/container_bridge.go index 88258ec90..eedab20da 100644 --- a/apis/server/container_bridge.go +++ b/apis/server/container_bridge.go @@ -174,7 +174,7 @@ func (s *Server) getContainers(ctx context.Context, rw http.ResponseWriter, req ImageID: c.Image, Command: strings.Join(c.Config.Cmd, " "), Status: status, - Created: t.UnixNano(), + Created: t.Unix(), Labels: c.Config.Labels, HostConfig: c.HostConfig, NetworkSettings: netSettings, diff --git a/cli/history.go b/cli/history.go index d4ad5931a..c7c578c4b 100644 --- a/cli/history.go +++ b/cli/history.go @@ -91,7 +91,7 @@ func (h *HistoryCommand) runHistory(args []string) error { } if h.flagHuman { - created, err = utils.FormatTimeInterval(entry.Created) + created, err = utils.FormatTimeInterval(0, entry.Created) if err != nil { return err } diff --git a/cli/ps.go b/cli/ps.go index ec7d15fd9..48ae6424c 100644 --- a/cli/ps.go +++ b/cli/ps.go @@ -93,7 +93,7 @@ func (p *PsCommand) runPs(args []string) error { display.AddRow([]string{"Name", "ID", "Status", "Created", "Image", "Runtime"}) for _, c := range containers { - created, err := utils.FormatTimeInterval(c.Created) + created, err := utils.FormatTimeInterval(c.Created, 0) if err != nil { return err } @@ -160,7 +160,7 @@ func (c containerList) Swap(i, j int) { // Less implements the sort interface. func (c containerList) Less(i, j int) bool { - iValue := time.Unix(0, c[i].Created) - jValue := time.Unix(0, c[j].Created) + iValue := time.Unix(c[i].Created, 0) + jValue := time.Unix(c[j].Created, 0) return iValue.After(jValue) } diff --git a/daemon/mgr/container_types.go b/daemon/mgr/container_types.go index 7dfb4087c..1cb71303b 100644 --- a/daemon/mgr/container_types.go +++ b/daemon/mgr/container_types.go @@ -388,7 +388,7 @@ func (c *Container) FormatStatus() (string, error) { return "", err } - startAt, err := utils.FormatTimeInterval(start.UnixNano()) + startAt, err := utils.FormatTimeInterval(0, start.UnixNano()) if err != nil { return "", err } @@ -404,7 +404,7 @@ func (c *Container) FormatStatus() (string, error) { return "", err } - finishAt, err := utils.FormatTimeInterval(finish.UnixNano()) + finishAt, err := utils.FormatTimeInterval(0, finish.UnixNano()) if err != nil { return "", err } diff --git a/pkg/utils/timeutils.go b/pkg/utils/timeutils.go index d37c0abc6..1ca532823 100644 --- a/pkg/utils/timeutils.go +++ b/pkg/utils/timeutils.go @@ -31,8 +31,8 @@ const ( var errInvalid = errors.New("invalid time") // FormatTimeInterval is used to show the time interval from input time to now. -func FormatTimeInterval(input int64) (formattedTime string, err error) { - start := time.Unix(0, input) +func FormatTimeInterval(sec, nano int64) (formattedTime string, err error) { + start := time.Unix(sec, nano) diff := time.Since(start) // That should not happen. diff --git a/pkg/utils/timeutils_test.go b/pkg/utils/timeutils_test.go index f0b46f3c3..cc3bf706c 100644 --- a/pkg/utils/timeutils_test.go +++ b/pkg/utils/timeutils_test.go @@ -96,7 +96,7 @@ func TestFormatTimeInterval(t *testing.T) { err: errInvalid, }, } { - output, err := FormatTimeInterval(tc.input) + output, err := FormatTimeInterval(0, tc.input) assert.Equal(t, tc.err, err, tc.name) assert.Equal(t, tc.expected, output, tc.name) }