Skip to content

Commit

Permalink
month first weekday bug (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
davemilller authored Dec 7, 2023
1 parent 0512078 commit f5461a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ func (s *Scheduler) MonthFirstWeekday(weekday time.Weekday) *Scheduler {
return s.Cron(fmt.Sprintf("0 0 %d %d %d", day, month, weekday))
}

return s.Cron(fmt.Sprintf("0 0 %d %d %d", day, month+1, weekday))
return s.Cron(fmt.Sprintf("0 0 %d %d %d", day, (month+1)%12, weekday))
}

// LimitRunsTo limits the number of executions of this job to n.
Expand Down
5 changes: 5 additions & 0 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,11 @@ func TestScheduler_EveryMonthFirstWeekday(t *testing.T) {
expected: time.Date(2022, time.March, 7, 0, 0, 0, 0, time.UTC),
weekday: time.Monday,
},
{
current: time.Date(2022, time.December, 7, 0, 0, 0, 0, time.UTC),
expected: time.Date(2023, time.January, 2, 0, 0, 0, 0, time.UTC),
weekday: time.Monday,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit f5461a9

Please sign in to comment.