From 2e54d0b93cba2fd133edc32211dcc32c06ef72ca Mon Sep 17 00:00:00 2001 From: Alin Sinpalean Date: Fri, 17 Nov 2017 17:30:51 +0100 Subject: [PATCH] Use seconds instead of years for zero durations (#111) `0y` looks very, very weird. --- model/time.go | 3 +++ model/time_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/model/time.go b/model/time.go index 7e87f1ac..74ed5a9f 100644 --- a/model/time.go +++ b/model/time.go @@ -214,6 +214,9 @@ func (d Duration) String() string { ms = int64(time.Duration(d) / time.Millisecond) unit = "ms" ) + if ms == 0 { + return "0s" + } factors := map[string]int64{ "y": 1000 * 60 * 60 * 24 * 365, "w": 1000 * 60 * 60 * 24 * 7, diff --git a/model/time_test.go b/model/time_test.go index 45ffd872..3efdd65f 100644 --- a/model/time_test.go +++ b/model/time_test.go @@ -91,6 +91,9 @@ func TestParseDuration(t *testing.T) { out time.Duration }{ { + in: "0s", + out: 0, + }, { in: "324ms", out: 324 * time.Millisecond, }, {