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 #307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 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).replace(tzinfo=None)
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 Expand Up @@ -52,5 +52,5 @@ def rationalize_until(until=None):
elif isinstance(until, datetime):
until = to_unix(until)
elif isinstance(until, timedelta):
until = to_unix((datetime.utcnow() + until))
until = to_unix((datetime.now() + until))
return until
Loading