Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion telegram/ext/jobqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ class Days(object):
EVERY_DAY = tuple(range(7))


class UTC(datetime.tzinfo):
"""UTC"""

ZERO = datetime.timedelta(0)
HOUR = datetime.timedelta(hours=1)

def utcoffset(self, dt):
return ZERO

def tzname(self, dt):
return "UTC"

def dst(self, dt):
return ZERO


class JobQueue(object):
"""This class allows you to periodically perform tasks with the bot.

Expand Down Expand Up @@ -77,7 +93,11 @@ def _put(self, job, next_t=None, last_t=None):
raise ValueError('next_t is None')

if isinstance(next_t, datetime.datetime):
next_t = (next_t - datetime.datetime.now()).total_seconds()
if next_t.tzinfo == None:
next_t = (next_t - datetime.datetime.now()).total_seconds()
else:
next_t = next_t.astimezone(UTC()).replace(tzinfo=None)
next_t = (next_t - datetime.datetime.utcnow()).total_seconds()

elif isinstance(next_t, datetime.time):
next_datetime = datetime.datetime.combine(datetime.date.today(), next_t)
Expand Down