From bc833c9c8c90616826804ab2909b3916984e95ea Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 14 Nov 2017 16:40:34 -0600 Subject: [PATCH] Handle edge case when allocation create/modify time difference is less than a second ago. --- command/helpers.go | 6 +++++- command/helpers_test.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/command/helpers.go b/command/helpers.go index bf2f9dbbb..2154e2abe 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -181,7 +181,11 @@ func prettyTimeDiff(first, second time.Time) string { if num_periods > 2 { end = indexes[num_periods-3] } - return string(buf[start:end]) + " ago" + if start == end { //edge case when time difference is less than a second + return "0s ago" + } else { + return string(buf[start:end]) + " ago" + } } diff --git a/command/helpers_test.go b/command/helpers_test.go index 617a732f3..6ac6dd7f7 100644 --- a/command/helpers_test.go +++ b/command/helpers_test.go @@ -300,6 +300,7 @@ func TestPrettyTimeDiff(t *testing.T) { d time.Duration exp string }{ + {-100 * time.Millisecond, "0s ago"}, {-740 * time.Second, "12m20s ago"}, {-12 * time.Minute, "12m ago"}, {-60 * time.Minute, "1h ago"},