Skip to content

Commit

Permalink
create time should in seconds instead of nano seconds
Browse files Browse the repository at this point in the history
Signed-off-by: frankyang <yyb196@gmail.com>
  • Loading branch information
yyb196 authored and zhuangqh committed Aug 5, 2019
1 parent 7dd5daf commit 17ba8c3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apis/server/container_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cli/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cli/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions daemon/mgr/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/timeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/timeutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 17ba8c3

Please sign in to comment.