For example, my local timezone is +3 UTC and I want to run job every working day at 23:00 UTC.
launch_time.tzinfo is None so it's expected to be interpreted as 23:00 UTC.
launch_time = dtm.time(hour=23)
job = job_queue.run_daily(run_once, launch_time,
days=(0, 1, 3, 4))
Since launch_time.tzinfo was None, job.tzinfo is also equals None because of the following code from JobQueue.run_daily
|
job = Job(callback, |
|
interval=datetime.timedelta(days=1), |
|
repeat=True, |
|
days=days, |
|
tzinfo=time.tzinfo, |
|
context=context, |
|
name=name, |
|
job_queue=self) |
Let's assume now is 23:00 UTC Friday.
The following code from JobQueue.tick won't run the job because
datetime.datetime.now(None) returns local time and local time now is 02:00 Saturday.
- then
datetime.datetime.now(job.tzinfo).date().weekday() will return 5
any(day == current_week_day for day in job.days) will return False because we're looking for (0, 1, 3, 4)
So job won't be run until 23:00 UTC Sunday.
|
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): |
|
self.logger.debug('Running job %s', job.name) |
|
job.run(self._dispatcher) |
And one more thing - when #1685 will be merged, in the described case Job.next_t will be returning local time when utc time is expected:
@property
def next_t(self):
return datetime.datetime.fromtimestamp(self._next_t, self.tzinfo) if self._next_t else None
For example, my local timezone is +3 UTC and I want to run job every working day at 23:00 UTC.
launch_time.tzinfoisNoneso it's expected to be interpreted as 23:00 UTC.Since
launch_time.tzinfowasNone,job.tzinfois also equalsNonebecause of the following code fromJobQueue.run_dailypython-telegram-bot/telegram/ext/jobqueue.py
Lines 225 to 232 in 3d42df3
Let's assume now is 23:00 UTC Friday.
The following code from
JobQueue.tickwon't run the job becausedatetime.datetime.now(None)returns local time and local time now is 02:00 Saturday.datetime.datetime.now(job.tzinfo).date().weekday()will return5any(day == current_week_day for day in job.days)will returnFalsebecause we're looking for(0, 1, 3, 4)So job won't be run until 23:00 UTC Sunday.
python-telegram-bot/telegram/ext/jobqueue.py
Lines 275 to 280 in 3d42df3
And one more thing - when #1685 will be merged, in the described case
Job.next_twill be returning local time when utc time is expected: