-
Notifications
You must be signed in to change notification settings - Fork 48
/
range.go
37 lines (30 loc) · 835 Bytes
/
range.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package parser
import (
"errors"
"fmt"
"strconv"
"strings"
)
// ParseIssuesRange the range of issues.
// Format [start-end].
func ParseIssuesRange(rng string) (float64, float64, error) {
values := strings.Split(rng, "-")
if len(values) != 2 {
return 0, 0, errors.New("wrong range format")
}
startRange, err := strconv.ParseFloat(values[0], 64)
if err != nil {
return 0, 0, fmt.Errorf("wrong the start range value: %v", err)
}
endRange, err := strconv.ParseFloat(values[1], 64)
if err != nil {
return 0, 0, fmt.Errorf("wrong the end range value: %v", err)
}
if endRange == 0 {
return 0, 0, errors.New("the end range value must not be zero")
}
if startRange > endRange {
return 0, 0, errors.New("the start range value must be less or equal to the end range value")
}
return startRange, endRange, nil
}