diff --git a/duration.go b/duration.go index f2ab7ff..d9a970a 100644 --- a/duration.go +++ b/duration.go @@ -144,6 +144,7 @@ func (d *Duration) UnmarshalText(data []byte) error { // validation is performed func ParseDuration(s string) (time.Duration, error) { // NOTE: this code is largely inspired by the standard library. orig := s + s = strings.TrimSpace(s) var d uint64 neg := false diff --git a/duration_test.go b/duration_test.go index 5052ee9..9ab05f8 100644 --- a/duration_test.go +++ b/duration_test.go @@ -162,6 +162,11 @@ func TestDurationParser(t *testing.T) { "1 m45 s": time.Minute + 45*time.Second, "1m 45s": time.Minute + 45*time.Second, "1 minute 45 seconds": time.Minute + 45*time.Second, + + // leading and trailing spaces + " 1s ": 1 * time.Second, + "1s ": 1 * time.Second, + " 1s": 1 * time.Second, } for str, dur := range testcases {