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] - switching daylight saving time doesn't work #318

Closed
wolfgang-braun opened this issue Mar 28, 2022 · 5 comments
Closed

[BUG] - switching daylight saving time doesn't work #318

wolfgang-braun opened this issue Mar 28, 2022 · 5 comments

Comments

@wolfgang-braun
Copy link

Describe the bug

Task gets executed an hour too late. Local time / location is correctly set.

To Reproduce

	location, err := time.LoadLocation("Europe/Berlin")
	if err != nil {
		panic(err)
	}
	s := gocron.NewScheduler(location)
	s.Every(1).Day().At("09:00").Do(logLocalTime)

Output:

2022/03/28 10:00:00 - logging local time: 2022-03-28 10:00:00

Expected behavior

2022/03/28 09:00:00 - logging local time: 2022-03-28 09:00:00

Version

github.com/go-co-op/gocron v1.13.0

Other

  • go 1.17
  • Docker container has been restarted after time change
  • Docker image:
FROM scratch
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /service /service
COPY --from=builder /logs /logs
COPY --from=builder /data /data
ENV TZ Europe/Berlin
ENTRYPOINT ["/service"]

Related

Thank you!

@JohnRoesler
Copy link
Contributor

hey @wolfgang-braun thanks for reporting. An hour sounds a lot like a daylight time issue. Does Europe/Berlin use daylight time?

@wolfgang-braun
Copy link
Author

Hi @JohnRoesler, yes it does. The switch was on Sunday. Using the former maintainers package a container restart did the trick.
I now switched to go 1.18 and the latest go alpine docker image and will check whether the issue persists.

Furthermore I can't reproduce it using playground

package main

import (
	"log"
	"time"

	"github.com/go-co-op/gocron"
)

func main() {
	location, err := time.LoadLocation("Europe/Berlin")
	if err != nil {
		panic(err)
	}
	logLocalTime(location)
	s := gocron.NewScheduler(location)
	s.Every(1).Day().At("00:00:05").Do(logLocalTime, location)
	s.StartBlocking()
}

func logLocalTime(location *time.Location) {
	log.Println("Europe/Berlin time: ", time.Now().In(location).Format("2006-01-02 15:04:05"))
}
2009/11/10 23:00:00 Europe/Berlin time:  2009-11-11 00:00:00
2009/11/10 23:00:05 Europe/Berlin time:  2009-11-11 00:00:05

This behavior is actually expected: .At("00:00:05") prints 2009-11-11 00:00:05 while the system/application time is 2009/11/10 23:00:05

One difference compared to my use case is that system/application time zone = cron time zone.

@franklinkim
Copy link

Can confirm the behaviour, ran into the same issue.

@JohnRoesler
Copy link
Contributor

Did this resolve? We had a similar issue a while ago that was related to the underlying docker container the app was being run in. I'm inclined to suspect something with the host system's time / tz files being the cause of this issue.

@JohnRoesler
Copy link
Contributor

reopen if this is still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants