-
Notifications
You must be signed in to change notification settings - Fork 32
/
check_command.go
50 lines (39 loc) · 1.13 KB
/
check_command.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
43
44
45
46
47
48
49
50
package resource
import (
"time"
"github.com/concourse/time-resource/lord"
"github.com/concourse/time-resource/models"
)
type CheckCommand struct {
}
func (*CheckCommand) Run(request models.CheckRequest) ([]models.Version, error) {
err := request.Source.Validate()
if err != nil {
return nil, err
}
previousTime := request.Version.Time
currentTime := time.Now().UTC()
specifiedLocation := request.Source.Location
if specifiedLocation != nil {
currentTime = currentTime.In((*time.Location)(specifiedLocation))
}
tl := lord.TimeLord{
PreviousTime: previousTime,
Location: specifiedLocation,
Start: request.Source.Start,
Stop: request.Source.Stop,
Interval: request.Source.Interval,
Days: request.Source.Days,
}
versions := []models.Version{}
if !previousTime.IsZero() {
versions = append(versions, models.Version{Time: previousTime})
} else if request.Source.InitialVersion {
versions = append(versions, models.Version{Time: currentTime})
return versions, nil
}
if tl.Check(currentTime) {
versions = append(versions, models.Version{Time: currentTime})
}
return versions, nil
}