forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch_time.go
42 lines (34 loc) · 927 Bytes
/
watch_time.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
38
39
40
41
42
package manifest
import (
"strconv"
"strings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type WatchTime struct {
Start int
End int
}
func NewWatchTime(timeRange string) (WatchTime, error) {
parts := strings.Split(timeRange, "-")
if len(parts) != 2 {
return WatchTime{}, bosherr.Errorf("Invalid watch time range '%s'", timeRange)
}
start, err := strconv.Atoi(strings.Trim(parts[0], " "))
if err != nil {
return WatchTime{}, bosherr.WrapErrorf(
err, "Non-positive number as watch time minimum %s", parts[0])
}
end, err := strconv.Atoi(strings.Trim(parts[1], " "))
if err != nil {
return WatchTime{}, bosherr.WrapErrorf(
err, "Non-positive number as watch time maximum %s", parts[1])
}
if end < start {
return WatchTime{}, bosherr.Errorf(
"Watch time must have maximum greater than or equal minimum %s", timeRange)
}
return WatchTime{
Start: start,
End: end,
}, nil
}