Skip to content

Commit

Permalink
fix next fire calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Nov 13, 2020
1 parent 52e49ad commit 6f68e82
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/rp-archiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ func main() {
}

for {
start := time.Now().In(time.UTC)

// convert the starttime to time.Time
layout := "15:04"
start, err := time.Parse(layout, config.StartTime)
hour, err := time.Parse(layout, config.StartTime)
if err != nil {
logrus.WithError(err).Fatal("invalid start time supplied, format: HH:mm")
}
Expand Down Expand Up @@ -124,7 +126,16 @@ func main() {
if config.ExitOnCompletion {
break
}
nextDay := start.AddDate(0, 0, 1)

// build up our next start
now := time.Now().In(time.UTC)
nextDay := time.Date(now.Year(), now.Month(), now.Day(), hour.Hour(), hour.Minute(), 0, 0, time.UTC)

// if this time is before our actual start, add a day
if nextDay.Before(start) {
nextDay = nextDay.AddDate(0, 0, 1)
}

napTime := nextDay.Sub(time.Now().In(time.UTC))

if napTime > time.Duration(0) {
Expand Down

0 comments on commit 6f68e82

Please sign in to comment.