Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create time should in seconds instead of nano seconds #2955

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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