Skip to content

Commit 17ba8c3

Browse files
yyb196zhuangqh
authored andcommitted
create time should in seconds instead of nano seconds
Signed-off-by: frankyang <[email protected]>
1 parent 7dd5daf commit 17ba8c3

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

apis/server/container_bridge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (s *Server) getContainers(ctx context.Context, rw http.ResponseWriter, req
174174
ImageID: c.Image,
175175
Command: strings.Join(c.Config.Cmd, " "),
176176
Status: status,
177-
Created: t.UnixNano(),
177+
Created: t.Unix(),
178178
Labels: c.Config.Labels,
179179
HostConfig: c.HostConfig,
180180
NetworkSettings: netSettings,

cli/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (h *HistoryCommand) runHistory(args []string) error {
9191
}
9292

9393
if h.flagHuman {
94-
created, err = utils.FormatTimeInterval(entry.Created)
94+
created, err = utils.FormatTimeInterval(0, entry.Created)
9595
if err != nil {
9696
return err
9797
}

cli/ps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (p *PsCommand) runPs(args []string) error {
9393
display.AddRow([]string{"Name", "ID", "Status", "Created", "Image", "Runtime"})
9494

9595
for _, c := range containers {
96-
created, err := utils.FormatTimeInterval(c.Created)
96+
created, err := utils.FormatTimeInterval(c.Created, 0)
9797
if err != nil {
9898
return err
9999
}
@@ -160,7 +160,7 @@ func (c containerList) Swap(i, j int) {
160160

161161
// Less implements the sort interface.
162162
func (c containerList) Less(i, j int) bool {
163-
iValue := time.Unix(0, c[i].Created)
164-
jValue := time.Unix(0, c[j].Created)
163+
iValue := time.Unix(c[i].Created, 0)
164+
jValue := time.Unix(c[j].Created, 0)
165165
return iValue.After(jValue)
166166
}

daemon/mgr/container_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (c *Container) FormatStatus() (string, error) {
388388
return "", err
389389
}
390390

391-
startAt, err := utils.FormatTimeInterval(start.UnixNano())
391+
startAt, err := utils.FormatTimeInterval(0, start.UnixNano())
392392
if err != nil {
393393
return "", err
394394
}
@@ -404,7 +404,7 @@ func (c *Container) FormatStatus() (string, error) {
404404
return "", err
405405
}
406406

407-
finishAt, err := utils.FormatTimeInterval(finish.UnixNano())
407+
finishAt, err := utils.FormatTimeInterval(0, finish.UnixNano())
408408
if err != nil {
409409
return "", err
410410
}

pkg/utils/timeutils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const (
3131
var errInvalid = errors.New("invalid time")
3232

3333
// FormatTimeInterval is used to show the time interval from input time to now.
34-
func FormatTimeInterval(input int64) (formattedTime string, err error) {
35-
start := time.Unix(0, input)
34+
func FormatTimeInterval(sec, nano int64) (formattedTime string, err error) {
35+
start := time.Unix(sec, nano)
3636
diff := time.Since(start)
3737

3838
// That should not happen.

pkg/utils/timeutils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestFormatTimeInterval(t *testing.T) {
9696
err: errInvalid,
9797
},
9898
} {
99-
output, err := FormatTimeInterval(tc.input)
99+
output, err := FormatTimeInterval(0, tc.input)
100100
assert.Equal(t, tc.err, err, tc.name)
101101
assert.Equal(t, tc.expected, output, tc.name)
102102
}

0 commit comments

Comments
 (0)