Skip to content

Commit

Permalink
Use seconds instead of years for zero durations (weaveworks#111)
Browse files Browse the repository at this point in the history
`0y` looks very, very weird.
  • Loading branch information
alin-amana authored and brian-brazil committed Nov 17, 2017
1 parent e3fb1a1 commit 2e54d0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions model/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions model/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func TestParseDuration(t *testing.T) {
out time.Duration
}{
{
in: "0s",
out: 0,
}, {
in: "324ms",
out: 324 * time.Millisecond,
}, {
Expand Down

0 comments on commit 2e54d0b

Please sign in to comment.