From ddee93250004e9790bf0183fc4824fe4d2959afb Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 11 Dec 2017 15:58:24 -0800 Subject: [PATCH] Fix upgrade path of modify time --- command/helpers.go | 2 +- command/helpers_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/command/helpers.go b/command/helpers.go index 3130d0bbe..690220597 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -94,7 +94,7 @@ func fmtInt(buf []byte, v uint64) int { // is 10 months, 12 days, 3 hours and 2 seconds, the string "10mo12d" is returned. Zero values return the empty string func prettyTimeDiff(first, second time.Time) string { // handle zero values - if first.IsZero() { + if first.IsZero() || first.UnixNano() == 0 { return "" } // round to the nearest second diff --git a/command/helpers_test.go b/command/helpers_test.go index ddf9bf2a4..a639a6dfd 100644 --- a/command/helpers_test.go +++ b/command/helpers_test.go @@ -302,6 +302,8 @@ func TestPrettyTimeDiff(t *testing.T) { t2 time.Time exp string }{ + {now, time.Unix(0, 0), ""}, // This is the upgrade path case + {now, now.Add(-10 * time.Millisecond), "0s ago"}, {now, now.Add(-10 * time.Millisecond), "0s ago"}, {now, now.Add(-740 * time.Second), "12m20s ago"}, {now, now.Add(-12 * time.Minute), "12m ago"},