diff --git a/telegram/ext/jobqueue.py b/telegram/ext/jobqueue.py index e17957342..058bf5904 100644 --- a/telegram/ext/jobqueue.py +++ b/telegram/ext/jobqueue.py @@ -285,7 +285,7 @@ class JobQueue(object): if job.enabled: try: current_week_day = datetime.datetime.now(job.tzinfo).date().weekday() - if any(day == current_week_day for day in job.days): + if current_week_day in job.days: self.logger.debug('Running job %s', job.name) job.run(self._dispatcher) @@ -400,7 +400,7 @@ class Job(object): days=Days.EVERY_DAY, name=None, job_queue=None, - tzinfo=_UTC): + tzinfo=None): self.callback = callback self.context = context @@ -413,7 +413,7 @@ class Job(object): self._days = None self.days = days - self.tzinfo = tzinfo + self.tzinfo = tzinfo or _UTC self._job_queue = weakref.proxy(job_queue) if job_queue is not None else None diff --git a/tests/test_jobqueue.py b/tests/test_jobqueue.py index 5bdefbfb0..7179f53bd 100644 --- a/tests/test_jobqueue.py +++ b/tests/test_jobqueue.py @@ -28,7 +28,7 @@ from flaky import flaky from telegram.ext import JobQueue, Updater, Job, CallbackContext from telegram.utils.deprecate import TelegramDeprecationWarning -from telegram.utils.helpers import _UtcOffsetTimezone +from telegram.utils.helpers import _UtcOffsetTimezone, _UTC @pytest.fixture(scope='function') @@ -330,3 +330,14 @@ class TestJobQueue(object): sleep(0.03) assert self.result == 0 + + def test_job_default_tzinfo(self, job_queue): + """Test that default tzinfo is always set to UTC""" + job_1 = job_queue.run_once(self.job_run_once, 0.01) + job_2 = job_queue.run_repeating(self.job_run_once, 10) + job_3 = job_queue.run_daily(self.job_run_once, time=dtm.time(hour=15)) + + jobs = [job_1, job_2, job_3] + + for job in jobs: + assert job.tzinfo == _UTC