diff --git a/errors.go b/errors.go index 04c3ffa..12eca67 100644 --- a/errors.go +++ b/errors.go @@ -9,6 +9,7 @@ var ( ErrDailyJobAtTimeNil = fmt.Errorf("gocron: DailyJob: atTime within atTimes must not be nil") ErrDailyJobAtTimesNil = fmt.Errorf("gocron: DailyJob: atTimes must not be nil") ErrDailyJobHours = fmt.Errorf("gocron: DailyJob: atTimes hours must be between 0 and 23 inclusive") + ErrDailyJobZeroInterval = fmt.Errorf("gocron: DailyJob: interval must be greater than 0") ErrDailyJobMinutesSeconds = fmt.Errorf("gocron: DailyJob: atTimes minutes and seconds must be between 0 and 59 inclusive") ErrDurationJobIntervalZero = fmt.Errorf("gocron: DurationJob: time interval is 0") ErrDurationRandomJobMinMax = fmt.Errorf("gocron: DurationRandomJob: minimum duration must be less than maximum duration") diff --git a/job.go b/job.go index ee206af..b342cd0 100644 --- a/job.go +++ b/job.go @@ -252,6 +252,10 @@ func (d dailyJobDefinition) setup(j *internalJob, location *time.Location, _ tim return ErrDailyJobMinutesSeconds } + if d.interval == 0 { + return ErrDailyJobZeroInterval + } + ds := dailyJob{ interval: d.interval, atTimes: atTimesDate, diff --git a/scheduler_test.go b/scheduler_test.go index a8c719b..609975e 100644 --- a/scheduler_test.go +++ b/scheduler_test.go @@ -607,6 +607,17 @@ func TestScheduler_NewJobErrors(t *testing.T) { nil, ErrDailyJobMinutesSeconds, }, + { + "daily job interval 0", + DailyJob( + 0, + NewAtTimes( + NewAtTime(1, 0, 0), + ), + ), + nil, + ErrDailyJobZeroInterval, + }, { "weekly job at times nil", WeeklyJob(