1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #12888 from jmzwcn/patch-3

`docker images` friendly duration gets unfriendly after a while
This commit is contained in:
Doug Davis 2015-05-03 11:09:25 -04:00
commit e8bbd87ba8
2 changed files with 4 additions and 3 deletions

View file

@ -26,6 +26,7 @@ func HumanDuration(d time.Duration) string {
return fmt.Sprintf("%d weeks", hours/24/7) return fmt.Sprintf("%d weeks", hours/24/7)
} else if hours < 24*365*2 { } else if hours < 24*365*2 {
return fmt.Sprintf("%d months", hours/24/30) return fmt.Sprintf("%d months", hours/24/30)
} else {
return fmt.Sprintf("%d years", hours/24/365)
} }
return fmt.Sprintf("%f years", d.Hours()/24/365)
} }

View file

@ -41,6 +41,6 @@ func TestHumanDuration(t *testing.T) {
assertEquals(t, "13 months", HumanDuration(13*month)) assertEquals(t, "13 months", HumanDuration(13*month))
assertEquals(t, "23 months", HumanDuration(23*month)) assertEquals(t, "23 months", HumanDuration(23*month))
assertEquals(t, "24 months", HumanDuration(24*month)) assertEquals(t, "24 months", HumanDuration(24*month))
assertEquals(t, "2.010959 years", HumanDuration(24*month+2*week)) assertEquals(t, "2 years", HumanDuration(24*month+2*week))
assertEquals(t, "3.164384 years", HumanDuration(3*year+2*month)) assertEquals(t, "3 years", HumanDuration(3*year+2*month))
} }