Improved timezones handling in next_run #604
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This improves how the timezone configured in
.at("18:00", "Europe/Amsterdam")
is processed.The problem is that the
self.next_run value
is localized toself.at_time_zone
and then converted to local time. In the next condition, the code usesdatetime.datetime.now()
, which fetches the current time in the local timezone. If the system's local timezone is different fromself.at_time_zone
, this can result in a discrepancy and cause the computation of self.next_run to be off by a day or more. This is what is happening in #603.This PR changes the timezone-handling approach to use localized datetimes throughout the whole
_schedule_next_run
function.PR created as draft since there are still a few untested cases that I would like to add tests for before merging. Especially in the area of combining
.at()
with weekdays,until()
and daylight-saving-time.