From 4c5146ab162e9605bd69d45750bcd4a42f7487e0 Mon Sep 17 00:00:00 2001 From: John Roesler Date: Thu, 31 Oct 2024 10:31:47 -0500 Subject: [PATCH] dailyjob should not allow interval zero --- errors.go | 1 + job.go | 4 ++++ scheduler_test.go | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/errors.go b/errors.go index 04c3ffa7..12eca676 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 ee206af1..b342cd02 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 a8c719b1..609975e0 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(