Skip to content

Commit

Permalink
Merge pull request #438 from ripcurld0/history_fix
Browse files Browse the repository at this point in the history
Print timestamp when --human=true
  • Loading branch information
thaJeztah authored Aug 14, 2017
2 parents b8d325e + 5e7f0f6 commit 898f1e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cli/command/formatter/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ func (c *historyContext) ID() string {
}

func (c *historyContext) CreatedAt() string {
return units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0)))
return time.Unix(c.h.Created, 0).Format(time.RFC3339)
}

func (c *historyContext) CreatedSince() string {
if !c.human {
return c.CreatedAt()
}
created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0)))
return created + " ago"
}
Expand Down
14 changes: 9 additions & 5 deletions cli/command/formatter/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ func TestHistoryContext_ID(t *testing.T) {
}

func TestHistoryContext_CreatedSince(t *testing.T) {
unixTime := time.Now().AddDate(0, 0, -7).Unix()
expected := "7 days ago"

var ctx historyContext
cases := []historyCase{
{
historyContext{
h: image.HistoryResponseItem{Created: unixTime},
h: image.HistoryResponseItem{Created: time.Now().AddDate(0, 0, -7).Unix()},
trunc: false,
human: true,
}, expected, ctx.CreatedSince,
}, "7 days ago", ctx.CreatedSince,
},
{
historyContext{
h: image.HistoryResponseItem{Created: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()},
trunc: false,
human: false,
}, "2009-11-10T23:00:00Z", ctx.CreatedSince,
},
}

Expand Down

0 comments on commit 898f1e2

Please sign in to comment.