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

Use correct UTC settings for crontab #300

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rq_scheduler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import crontab
import dateutil.tz

from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import logging

from rq.logutils import ColorizingStreamHandler
Expand All @@ -23,7 +23,7 @@ def to_unix(dt):
def get_next_scheduled_time(cron_string, use_local_timezone=False):
"""Calculate the next scheduled time by creating a crontab object
with a cron string"""
now = datetime.now()
now = datetime.now(timezone.utc)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better

    tz = dateutil.tz.tzlocal() if use_local_timezone else dateutil.tz.UTC
    now = datetime.now(tz)

cron = crontab.CronTab(cron_string)
next_time = cron.next(now=now, return_datetime=True)
tz = dateutil.tz.tzlocal() if use_local_timezone else dateutil.tz.UTC
Expand Down