Fix upgrade path of modify time

This commit is contained in:
Alex Dadgar 2017-12-11 15:58:24 -08:00
parent 66041b7a42
commit 189ff0dc22
2 changed files with 3 additions and 1 deletions

View File

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

View File

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