-
Notifications
You must be signed in to change notification settings - Fork 714
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 a daylight savings time issue in CronTrigger
#981
base: master
Are you sure you want to change the base?
Conversation
(1) remove the `timedelta` operations - which are not timezone aware (2) make sure the "fold" attribute remains when incrementing
How did you get the test to pass for you locally? Are the new tests sensitive to the local time zone? |
b46e605
to
f45bddb
Compare
for more information, see https://pre-commit.ci
Either way, I'll take a look at this tomorrow. |
Oh, and I'll need a new changelog entry for this too (don't delete the pull request template, as it contains a check list of things for the PR to be accepted). |
Oops, it's been 2 weeks already! I got distracted by several other projects I'm working on. Anyways, the workings of the cron trigger are not fresh in my memory, so would you mind explaining these changes? They look fine, but I'd like to understand why these specific changes were necessary. |
No problem ! self._last_fire_time + timedelta(seconds=1) by datetime.fromtimestamp(
self._last_fire_time.timestamp() + 1, self.timezone
) For any reason, the first one does not take DST into account.
The second one does the trick because it is doing operations using the
The other change is to make sure the value of This made my use cases pass, see the tests. And thanks for the great apscheduler ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, but I'd like a few tweaks before I merge.
assert next_date == correct_next_date.replace(tzinfo=timezone) | ||
assert next_date.fold == fold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would make me feel better about the correctness.
assert next_date == correct_next_date.replace(tzinfo=timezone) | |
assert next_date.fold == fold | |
assert next_date == correct_next_date.replace(tzinfo=timezone, fold=fold) | |
assert str(next_date) == str(correct_next_date) |
"cron_expression, start_time, correct_next_dates", | ||
[ | ||
( | ||
"0 * * * *", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why bother with from_crontab()
? This could just be the minute
field.
@@ -207,16 +207,17 @@ def _set_field_value( | |||
else: | |||
values[field.name] = new_value | |||
|
|||
return datetime(**values, tzinfo=self.timezone) | |||
return datetime(**values, tzinfo=self.timezone).replace(fold=dateval.fold) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return datetime(**values, tzinfo=self.timezone).replace(fold=dateval.fold) | |
return datetime(**values, tzinfo=self.timezone, fold=dateval.fold) |
Changes
Fixes #980.