mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-26 16:38:53 +01:00
Fix bug: unable to save jobs with timezone aware dates (#1308)
* Fix bug on jobs with timezone aware dates * Add Ambro17 as colaborator
This commit is contained in:
parent
7eeb670a59
commit
23fe991b85
3 changed files with 20 additions and 1 deletions
|
@ -16,6 +16,7 @@ Contributors
|
||||||
The following wonderful people contributed directly or indirectly to this project:
|
The following wonderful people contributed directly or indirectly to this project:
|
||||||
|
|
||||||
- `Alateas <https://github.com/alateas>`_
|
- `Alateas <https://github.com/alateas>`_
|
||||||
|
- `Ambro17 <https://github.com/Ambro17>`_
|
||||||
- `Anton Tagunov <https://github.com/anton-tagunov>`_
|
- `Anton Tagunov <https://github.com/anton-tagunov>`_
|
||||||
- `Avanatiker <https://github.com/Avanatiker>`_
|
- `Avanatiker <https://github.com/Avanatiker>`_
|
||||||
- `Balduro <https://github.com/Balduro>`_
|
- `Balduro <https://github.com/Balduro>`_
|
||||||
|
|
|
@ -62,7 +62,7 @@ class JobQueue(object):
|
||||||
raise ValueError('next_t is None')
|
raise ValueError('next_t is None')
|
||||||
|
|
||||||
if isinstance(next_t, datetime.datetime):
|
if isinstance(next_t, datetime.datetime):
|
||||||
next_t = (next_t - datetime.datetime.now()).total_seconds()
|
next_t = (next_t - datetime.datetime.now(next_t.tzinfo)).total_seconds()
|
||||||
|
|
||||||
elif isinstance(next_t, datetime.time):
|
elif isinstance(next_t, datetime.time):
|
||||||
next_datetime = datetime.datetime.combine(datetime.date.today(), next_t)
|
next_datetime = datetime.datetime.combine(datetime.date.today(), next_t)
|
||||||
|
|
|
@ -184,6 +184,24 @@ class TestJobQueue(object):
|
||||||
sleep(0.06)
|
sleep(0.06)
|
||||||
assert pytest.approx(self.job_time) == expected_time
|
assert pytest.approx(self.job_time) == expected_time
|
||||||
|
|
||||||
|
def test_datetime_with_timezone_job_run_once(self, job_queue):
|
||||||
|
# Test that run_once jobs work with timezone aware datetimes.
|
||||||
|
offset = datetime.timedelta(hours=-3)
|
||||||
|
when = datetime.datetime.now(datetime.timezone(offset))
|
||||||
|
|
||||||
|
job_queue.run_once(self.job_run_once, when)
|
||||||
|
sleep(0.01)
|
||||||
|
assert self.result == 1
|
||||||
|
|
||||||
|
def test_datetime_with_timezone_job_run_repeating(self, job_queue):
|
||||||
|
# Test that run_repeating jobs work with timezone aware datetimes.
|
||||||
|
offset = datetime.timedelta(hours=5)
|
||||||
|
now_with_offset = datetime.datetime.now(datetime.timezone(offset))
|
||||||
|
|
||||||
|
job_queue.run_repeating(self.job_run_once, interval=0.01, first=now_with_offset)
|
||||||
|
sleep(0.015)
|
||||||
|
assert self.result == 2
|
||||||
|
|
||||||
def test_time_unit_dt_time_today(self, job_queue):
|
def test_time_unit_dt_time_today(self, job_queue):
|
||||||
# Testing running at a specific time today
|
# Testing running at a specific time today
|
||||||
delta = 0.05
|
delta = 0.05
|
||||||
|
|
Loading…
Add table
Reference in a new issue