mirror of https://github.com/docker/cli.git
Print timestamp when --human=true
* Setting "--human=true" changes "CreatedSince" format * "CreatedAt" now displays the creation timestamp as specified in the documents Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
This commit is contained in:
parent
4b61f560b5
commit
5e7f0f67a8
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue