From 28ea4a63d00e9d0e28375adc80d24461193e7a28 Mon Sep 17 00:00:00 2001 From: Daniel Zhang Date: Thu, 30 Apr 2015 13:38:54 +0800 Subject: [PATCH] `docker images` friendly duration gets unfriendly after a while fix #12852 Signed-off-by: Daniel Zhang --- pkg/units/duration.go | 3 ++- pkg/units/duration_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/units/duration.go b/pkg/units/duration.go index cd33121496..a31f780e3b 100644 --- a/pkg/units/duration.go +++ b/pkg/units/duration.go @@ -26,6 +26,7 @@ func HumanDuration(d time.Duration) string { return fmt.Sprintf("%d weeks", hours/24/7) } else if hours < 24*365*2 { 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) } diff --git a/pkg/units/duration_test.go b/pkg/units/duration_test.go index a22947402b..fcfb6b7bbd 100644 --- a/pkg/units/duration_test.go +++ b/pkg/units/duration_test.go @@ -41,6 +41,6 @@ func TestHumanDuration(t *testing.T) { assertEquals(t, "13 months", HumanDuration(13*month)) assertEquals(t, "23 months", HumanDuration(23*month)) assertEquals(t, "24 months", HumanDuration(24*month)) - assertEquals(t, "2.010959 years", HumanDuration(24*month+2*week)) - assertEquals(t, "3.164384 years", HumanDuration(3*year+2*month)) + assertEquals(t, "2 years", HumanDuration(24*month+2*week)) + assertEquals(t, "3 years", HumanDuration(3*year+2*month)) }