Merge pull request #438 from ripcurld0/history_fix

Print timestamp when --human=true
This commit is contained in:
Sebastiaan van Stijn 2017-08-14 16:02:04 +02:00 committed by GitHub
commit 898f1e2997
2 changed files with 13 additions and 6 deletions

View File

@ -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"
}

View File

@ -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,
},
}