Skip to content

Commit 4baf341

Browse files
authored
dailyjob should not allow interval zero (#791)
1 parent 838bd51 commit 4baf341

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var (
99
ErrDailyJobAtTimeNil = fmt.Errorf("gocron: DailyJob: atTime within atTimes must not be nil")
1010
ErrDailyJobAtTimesNil = fmt.Errorf("gocron: DailyJob: atTimes must not be nil")
1111
ErrDailyJobHours = fmt.Errorf("gocron: DailyJob: atTimes hours must be between 0 and 23 inclusive")
12+
ErrDailyJobZeroInterval = fmt.Errorf("gocron: DailyJob: interval must be greater than 0")
1213
ErrDailyJobMinutesSeconds = fmt.Errorf("gocron: DailyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
1314
ErrDurationJobIntervalZero = fmt.Errorf("gocron: DurationJob: time interval is 0")
1415
ErrDurationRandomJobMinMax = fmt.Errorf("gocron: DurationRandomJob: minimum duration must be less than maximum duration")

job.go

+4
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ func (d dailyJobDefinition) setup(j *internalJob, location *time.Location, _ tim
252252
return ErrDailyJobMinutesSeconds
253253
}
254254

255+
if d.interval == 0 {
256+
return ErrDailyJobZeroInterval
257+
}
258+
255259
ds := dailyJob{
256260
interval: d.interval,
257261
atTimes: atTimesDate,

scheduler_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,17 @@ func TestScheduler_NewJobErrors(t *testing.T) {
607607
nil,
608608
ErrDailyJobMinutesSeconds,
609609
},
610+
{
611+
"daily job interval 0",
612+
DailyJob(
613+
0,
614+
NewAtTimes(
615+
NewAtTime(1, 0, 0),
616+
),
617+
),
618+
nil,
619+
ErrDailyJobZeroInterval,
620+
},
610621
{
611622
"weekly job at times nil",
612623
WeeklyJob(

0 commit comments

Comments
 (0)