mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
Fix UTC as default tzinfo for Jobs (#1696)
1. Made sure that default tzinfo in JobQueue is UTC #1693. 2. Added test that checks that all methods by default set job.tzinfo as UTC.
This commit is contained in:
parent
e9cb6675ca
commit
9cb34af65a
2 changed files with 15 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue