Skip to content

Commit

Permalink
Treat durations without unit as hours
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmi committed Feb 26, 2022
1 parent 994d389 commit db80fb3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions luxwslang/terminology.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (*Terminology) ParseDuration(v string) (time.Duration, error) {
if n, err := fmt.Sscanf(v, "%d:%d:%d\n", &hours, &minutes, &seconds); err == nil && n == 3 {
} else if n, err := fmt.Sscanf(v, "%d:%d\n", &hours, &minutes); err == nil && n == 2 {
} else if n, err := fmt.Sscanf(v, "%dh\n", &hours); err == nil && n == 1 {
} else if n, err := fmt.Sscanf(v, "%d\n", &hours); err == nil && n == 1 {
} else {
return math.MinInt64, fmt.Errorf("unrecognized duration format %q: %w", v, err)
}
Expand Down
2 changes: 2 additions & 0 deletions luxwslang/terminology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func TestParseDuration(t *testing.T) {
{terms: German, input: "-100h", want: "-100h"},
{terms: German, input: " -23:1:2\n", want: "-23h1m2s"},
{terms: German, input: "-1:0:0", want: "-1h"},
{terms: German, input: "-100", want: "-100h"},
{terms: German, input: "123", want: "123h"},
{terms: German, input: "0:-1:0", wantErr: true},
{terms: German, input: "0:0:-1", wantErr: true},
} {
Expand Down

0 comments on commit db80fb3

Please sign in to comment.