diff --git a/scheduler.go b/scheduler.go index f51e0bde..e681fbe6 100644 --- a/scheduler.go +++ b/scheduler.go @@ -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. diff --git a/scheduler_test.go b/scheduler_test.go index 9edfbd87..14485a56 100644 --- a/scheduler_test.go +++ b/scheduler_test.go @@ -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 {