-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Support for tz-aware datetime.datetime objects #1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
## Original issue ## Issue: python-telegram-bot#1409 version: 12.0.0b1 ## Changes ## The `._put()` method can now accept utc_offset-aware/timezone-aware `datetime.datetime` objects. This helps bots to be hosted on a server with any timezone without complications. To convert datetimes to UTC, a "UTC" subclass of the `datetime.tzinfo` class was added, and used in `._put()`. ## Other options considered ## - Changing all the `.now()` comparisons in `._put()` to `.utcnow()`. This was not chosen, since it would cause a major compatibility issue. Bots would have to be rewritten to pass in UTC datetimes, instead of local (computer time) datetimes, into the jobqueue.run_once and other methods. This would likely be unwanted behaivour.
Hi @torresjrjr Could you add those please? |
Actually, I like to open this for discussion with the other maintainers. |
@tsnoam the point they make in the issue, is that sometimes you want to use |
Well, that's a subset of what a timezone is. |
Actually, I'm not so invested in this PR as much, since this was an attempt at a solution to a problem I later solved. I wanted to "help my bot to be hosted on a server with any timezone without complications" but I ended up simply adding an extra step in my code. I created a I should also stress that I'm a python noob/intermediate. I find PRs scary. So please, take my idea and do what you will. Thanks. |
We were debating whether this should be a here, in helpers or in the programmers hands. I guess you helped us answering that. I'm closing this PR. |
Original issue
Issue: #1409
version: 12.0.0b1
Changes
The
._put()
method can now accept utc_offset-aware/timezone-awaredatetime.datetime
objects. This helps bots to be hosted on a server with any timezone without complications.To convert datetimes to UTC, a "UTC" subclass of the
datetime.tzinfo
class was added, and used in._put()
.Other options considered
.now()
comparisons in._put()
to.utcnow()
. This was not chosen, since it would cause a major compatibility issue. Bots would have to be rewritten to pass in UTC datetimes, instead of local (computer time) datetimes, into the jobqueue.run_once and other methods. This would likely be unwanted behaivour.