Handle edge case when allocation create/modify time difference is less than a second ago.
This commit is contained in:
parent
0e6484a397
commit
03ac677dc8
|
@ -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"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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"},
|
||||
|
|
Loading…
Reference in New Issue