From 9eb894e489ed263d9ae75450ef22fe3a4ced7f90 Mon Sep 17 00:00:00 2001 From: dewalujjwal Date: Mon, 11 Mar 2024 22:51:38 +0530 Subject: [PATCH 1/2] added timezone info --- rq_scheduler/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rq_scheduler/utils.py b/rq_scheduler/utils.py index c34ab02..5bfbe75 100644 --- a/rq_scheduler/utils.py +++ b/rq_scheduler/utils.py @@ -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 @@ -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) 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 From 2f0e7e6228b952787d8dbf7c230c2d78f4d7fdb6 Mon Sep 17 00:00:00 2001 From: dewalujjwal Date: Mon, 11 Mar 2024 22:57:07 +0530 Subject: [PATCH 2/2] added timezone info --- rq_scheduler/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rq_scheduler/utils.py b/rq_scheduler/utils.py index 5bfbe75..f9d7a71 100644 --- a/rq_scheduler/utils.py +++ b/rq_scheduler/utils.py @@ -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(timezone.utc) + 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 @@ -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