gorhill / cronexpr

Cron expression parser in Go language (golang)
683 stars 168 forks source link

Wrong calculation on next schedule on cron expression: "*/5 * * * *" #25

Closed etsangsplk closed 7 years ago

etsangsplk commented 7 years ago

cronExpression= "/5 *"<-- this is every 5 minutes prints out from log: now=2017-03-25 15:38:11.667843072 -0700 PDT next_schedule=[2017-03-25 15:40:00 -0700 PDT] sec_diff=109" <-- 109 secs?

e, err = cronexpr.Parse(aws.StringValue(cronExpression)) base := time.Now() next := e.NextN(base, 1) // normalize before subtraction to Unix Time d := int(next[0].Unix() - base.Unix()) logging.Infof("now=%s next_schedule=%s sec_diff=%d", base, next, d)

etsangsplk commented 7 years ago

turns out this is my fault of musunderstanding. And I should have compare 2 subsequent schedules instead of now