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

[BUG] - Scheduler.NextRun() always returns 0001-01-01 00:00:00 +0000 UTC #574

Closed
bbaa-bbaa opened this issue Sep 21, 2023 · 0 comments · Fixed by #575
Closed

[BUG] - Scheduler.NextRun() always returns 0001-01-01 00:00:00 +0000 UTC #574

bbaa-bbaa opened this issue Sep 21, 2023 · 0 comments · Fixed by #575
Labels
bug Something isn't working

Comments

@bbaa-bbaa
Copy link

Describe the bug

To Reproduce

Example

s2 := gocron.NewScheduler(time.UTC)
s2.StartAsync()
s2.Every(1).Friday().At("20:19").Do(func() {})
fmt.Println(s2.NextRun())

The output :

<nil> 0001-01-01 00:00:00 +0000 UTC

Version

v1.34.1

Expected behavior

Return to the correct Job and time

Additional context

gocron/scheduler.go

Lines 522 to 531 in 01fcdee

var nearestRun time.Time
for _, job := range s.jobsMap() {
nr := job.NextRun()
if nr.Before(nearestRun) && s.now().Before(nr) {
nearestRun = nr
jobID = job.id
}
}
return s.jobsMap()[jobID], nearestRun

The variable nearestRun is initialized to 0001-01-01 00:00:00 +0000 UTC
It looks like nr.Before(nearestRun) will always be false

@bbaa-bbaa bbaa-bbaa added the bug Something isn't working label Sep 21, 2023
JohnRoesler added a commit that referenced this issue Sep 21, 2023
* fix Scheduler.NextRun() not returning the correct value

* if the nearest run is zero we'll never be before it

---------

Co-authored-by: John Roesler <johnrroesler@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant