From 5e7f0f67a81aac86605fa0498b2fe50bd5442ae0 Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Sat, 12 Aug 2017 21:38:01 +0300 Subject: [PATCH] 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 --- cli/command/formatter/history.go | 5 ++++- cli/command/formatter/history_test.go | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cli/command/formatter/history.go b/cli/command/formatter/history.go index 161aaa4b0044..c01b5415983c 100644 --- a/cli/command/formatter/history.go +++ b/cli/command/formatter/history.go @@ -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" } diff --git a/cli/command/formatter/history_test.go b/cli/command/formatter/history_test.go index a1ee205b0351..6b2c55e677d4 100644 --- a/cli/command/formatter/history_test.go +++ b/cli/command/formatter/history_test.go @@ -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, }, }