-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from owenfarrell/command
Extract business logic to base package
- Loading branch information
Showing
14 changed files
with
351 additions
and
402 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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}) | ||
} | ||
|
||
if tl.Check(currentTime) { | ||
versions = append(versions, models.Version{Time: currentTime}) | ||
} | ||
|
||
return versions, nil | ||
} |
Oops, something went wrong.