[GH-ISSUE #196] Problem with cron expressions #140

Closed
opened 2026-02-25 23:41:19 +03:00 by kerem · 6 comments
Owner

Originally created by @LordMike on GitHub (Oct 22, 2018).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/196

Hi,

Very odd. The cron expression engine does not accept 0 2 * * *... It accepts 0 1 * * * and 0 3 * * *.

image

image

image

Originally created by @LordMike on GitHub (Oct 22, 2018). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/196 Hi, Very odd. The cron expression engine does not accept `0 2 * * *`... It accepts `0 1 * * *` and `0 3 * * *`. ![image](https://user-images.githubusercontent.com/1027111/47313789-1f871e80-d640-11e8-9b4c-4cb36e524494.png) ![image](https://user-images.githubusercontent.com/1027111/47313802-2746c300-d640-11e8-9dda-ca75e8cfcb7c.png) ![image](https://user-images.githubusercontent.com/1027111/47313827-3fb6dd80-d640-11e8-9500-03647f997f70.png)
kerem closed this issue 2026-02-25 23:41:19 +03:00
Author
Owner

@cuu508 commented on GitHub (Oct 22, 2018):

Thanks for reporting, looks like a bug indeed. It has something to do with time zones: if I select timezone "Europe/Riga", then "0 2 * * *" works but "0 3 * * *" does not.

Will look into this as soon as I can.

<!-- gh-comment-id:431948564 --> @cuu508 commented on GitHub (Oct 22, 2018): Thanks for reporting, looks like a bug indeed. It has something to do with time zones: if I select timezone "Europe/Riga", then "0 2 * * *" works but "0 3 * * *" does not. Will look into this as soon as I can.
Author
Owner

@LordMike commented on GitHub (Oct 22, 2018):

Indeed. Denmark/Copenhagen should be at +2 now, but we're changing in a few days (28th).

I imagine that's the issue. If I go for once a month, I get the correct offsets (we go to +1 there):

image

... but then this works, so maybe that was a red herring..

image

( I tested with Berlin, but Copenhagen is the same )

<!-- gh-comment-id:431950934 --> @LordMike commented on GitHub (Oct 22, 2018): Indeed. Denmark/Copenhagen should be at +2 now, but we're changing in a few days (28th). I imagine that's the issue. If I go for once a month, I get the correct offsets (we go to +1 there): ![image](https://user-images.githubusercontent.com/1027111/47314436-efd91600-d641-11e8-91ce-472fc2d4810f.png) ... but then this works, so maybe that was a red herring.. ![image](https://user-images.githubusercontent.com/1027111/47314455-02ebe600-d642-11e8-941e-e1ed733f2dc0.png) ( I tested with Berlin, but Copenhagen is the same )
Author
Owner

@cuu508 commented on GitHub (Oct 23, 2018):

This was indeed due to DST transitions. When clocks are rolled one hour back or forward, some local times happen twice and some are skipped over. Worked around the ambiguity but will need to do more investigation on how to best handle time jumps in March when DST starts.

This is a hairy problem. I would recommend to keep things simple and:

  • use UTC on your servers
  • if you're not using UTC, avoid scheduling cron jobs around 2-3AM local time ;-)
<!-- gh-comment-id:432381076 --> @cuu508 commented on GitHub (Oct 23, 2018): This was indeed due to DST transitions. When clocks are rolled one hour back or forward, some local times happen *twice* and some are skipped over. Worked around the ambiguity but will need to do more investigation on how to best handle time jumps in March when DST starts. This is a hairy problem. I would recommend to keep things simple and: * use UTC on your servers * if you're not using UTC, avoid scheduling cron jobs around 2-3AM local time ;-)
Author
Owner

@pkoziol commented on GitHub (Oct 29, 2018):

handle time jumps in March when DST starts

I believe European Commision (or Parliament?) voted/recommended recently to stop using DST, so this was probably the last time we changed our clocks in (most of?) the Europe.

<!-- gh-comment-id:434099388 --> @pkoziol commented on GitHub (Oct 29, 2018): > handle time jumps in March when DST starts I believe European Commision (or Parliament?) voted/recommended recently to stop using DST, so this was probably the last time we changed our clocks in (most of?) the Europe.
Author
Owner

@LordMike commented on GitHub (Oct 31, 2018):

They're not done yet. It's still in discussion, and the timetable differes between 2019 and 2021. We'll see :P

<!-- gh-comment-id:434825124 --> @LordMike commented on GitHub (Oct 31, 2018): They're not done yet. It's still in discussion, and the timetable differes between 2019 and 2021. We'll see :P
Author
Owner

@cuu508 commented on GitHub (Dec 14, 2018):

This project is using croniter (https://github.com/kiorky/croniter/) to parse and evaluate cron expressions.

Apparently croniter does work with timezone-aware datetimes too. Just updated Healthchecks to pass timezone-aware datetimes to croniter. By avoiding aware-naive-aware conversions we also avoid the ambiguities around DST transitions.

<!-- gh-comment-id:447283373 --> @cuu508 commented on GitHub (Dec 14, 2018): This project is using croniter (https://github.com/kiorky/croniter/) to parse and evaluate cron expressions. Apparently croniter does work with timezone-aware datetimes too. Just updated Healthchecks to pass timezone-aware datetimes to croniter. By avoiding aware-naive-aware conversions we also avoid the ambiguities around DST transitions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/healthchecks#140
No description provided.