Handle edge case when allocation create/modify time difference is less than a second ago.

This commit is contained in:
Preetha Appan 2017-11-14 16:40:34 -06:00
parent 0e6484a397
commit 03ac677dc8
2 changed files with 6 additions and 1 deletions

View File

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

View File

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