Fix UTC/local inconsistencies for naive datetimes#1506
Fix UTC/local inconsistencies for naive datetimes#1506tsnoam merged 14 commits intopython-telegram-bot:masterfrom
Conversation
(cherry-picked from c6dd3d7. I've included the refactoring mentioned in python-telegram-bot#1497 to facilitate the change.) There was inconsistent use of UTC vs local times. For instance, in the former `_timestamp` helper (now `_datetime_to_float_timestamp`), assumed that naive `datetime.datetime` objects were in the local timezone, while the `from_timestamp` helper —which I would have thought was the corresponding inverse function— returned naïve objects in UTC. This meant that, for instance, `telegram.Message` objects' `date` field was constructed as a naïve `datetime.datetime` (from the timestamp sent by Telegram's server) in *UTC*, but when it was stored in `JSON` format through the `to_json` method, the naïve `date` would be assumed to be in *local time*, thus generating a different timestamp from the one it was built from. See python-telegram-bot#1505 for extended discussion.
Some tests/test fixtures that were using `datetime.datetime.now()` as a test value, were changed to `datetime.datetime.utcnow()`, since now everything is (hopefully) expecting UTC for naive datetimes.
jh0ker
left a comment
There was a problem hiding this comment.
Looks pretty good to me. I left two comments, if you could address them that would be great.
|
Some more questions that popped up during the discussion in the dev group. Are timezone-aware datetimes in the job queue supported with this? Were they supported before? There seem to be no tests for this yet. |
Yes; namely,
No; for example you would get a
Will add in the near future. |
|
Thank you very much! This looks very nice to me, but timezones confuse me so i requested a review from @tsnoam 😉 |
tsnoam
left a comment
There was a problem hiding this comment.
All in all, this is really great. Thank you!
However, I have several comments / changes needs to be done.
Will you be so kind to check them out?
|
@tsnoam Before merging I think I should add:
Anything else/any thoughts? |
tsnoam
left a comment
There was a problem hiding this comment.
Hi @plammens
This looks very good. Almost ready for merge :-)
- About the tests: yes, we need tests... also the tests @jh0ker had suggested in his review.
- I don't think any extra documentation is required for now. The docstring of
to_float_timestampis good enough. - Re: renaming funciton names - see the comments on the review notes. But basically, leave it as is.
- Still need to fix
JobQueue._put()so it won't passNonetoto_float_timestamp(). - Adding similar capabilities to
from_timestamp()can be done in a different PR. Lets wrap this one and merge it already ;-)
9da9dc1 to
5d11c26
Compare
|
@tsnoam I've addressed the remaining points and added tests. Sorry for the delay! |
A job shouldn't (and can't) be enqueued with `next_t = None`. An exception should be raised at `_put` before an obscure error occurs later down the line.
5d11c26 to
f962c6d
Compare
0c29dce to
1396ca9
Compare
|
@plammens |
|
I don't know why pre-commit test failed. On my machine it passes successfully. |
Closes #1505.