Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down