Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix calculateMonths #104

Merged
merged 5 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *Scheduler) calculateMonths(job *Job, lastRun time.Time) time.Duration {
nextRun = nextRun.AddDate(0, int(job.interval), daysDifference)
}
}
return s.until(lastRunRoundedMidnight, nextRun)
return s.until(lastRun, nextRun)
leoshus marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdw2330976 do you have a time scenario where this fails with lastRunRoundedMidnight? We can fake the time for a test, but ideally we could prove the old logic doesn't work with our test

}
nextRun := lastRunRoundedMidnight.Add(job.getAtTime()).AddDate(0, int(job.interval), 0)
return s.until(lastRunRoundedMidnight, nextRun)
Expand Down
10 changes: 10 additions & 0 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,13 @@ func TestRemoveAfterExec(t *testing.T) {

assert.Zero(t, len(s.Jobs()))
}

func TestCalculateMonths(t *testing.T) {
s := NewScheduler(time.Local)
s.StartAsync()
job, _ := s.Every(1).Month(1).At("10:00").Do(func() {
fmt.Println("hello task")
})
fmt.Println(job.ScheduledTime().Format("2006-01-02 15:04:05"))
time.Sleep(2 * time.Second)
}
leoshus marked this conversation as resolved.
Show resolved Hide resolved