Skip to content

Commit 537d6a4

Browse files
authored
Merge pull request #25 from choria-io/24
(#24) handle 0 as a special case duration
2 parents 31c4e55 + 4139882 commit 537d6a4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

duration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestDurationParser(t *testing.T) {
2020
{"1Y1M", (365 * 24 * time.Hour) + (24 * 30 * time.Hour), nil},
2121
{"1xX", 0, fmt.Errorf("%w: invalid unit xX", errInvalidDuration)},
2222
{"-1", 0, fmt.Errorf("invalid duration")},
23+
{"0", 0, nil},
2324
}
2425

2526
for _, c := range cases {

durations.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ var (
3030
//
3131
// Valid duration strings can be -1y1d1µs
3232
func ParseDuration(d string) (time.Duration, error) {
33+
// golang time.ParseDuration has a special case for 0
34+
if d == "0" {
35+
return 0 * time.Second, nil
36+
}
37+
3338
var (
3439
r time.Duration
3540
neg = 1

0 commit comments

Comments
 (0)