- Notifications
You must be signed in to change notification settings - Fork5.7k
Fix UTC/local inconsistencies for naive datetimes#1506
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
(cherry-picked fromc6dd3d7.I've included the refactoring mentioned inpython-telegram-bot#1497 to facilitate thechange.)There was inconsistent use of UTC vs local times. For instance, in theformer `_timestamp` helper (now `_datetime_to_float_timestamp`), assumedthat naive `datetime.datetime` objects were in the local timezone, whilethe `from_timestamp` helper —which I would have thought was thecorresponding inverse function— returned naïve objects in UTC.This meant that, for instance, `telegram.Message` objects' `date` fieldwas constructed as a naïve `datetime.datetime` (from the timestamp sentby Telegram's server) in *UTC*, but when it was stored in `JSON` formatthrough 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 wasbuilt from.Seepython-telegram-bot#1505 for extended discussion.
Some tests/test fixtures that were using `datetime.datetime.now()` asa test value, were changed to `datetime.datetime.utcnow()`, since noweverything is (hopefully) expecting UTC for naive datetimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks pretty good to me. I left two comments, if you could address them that would be great.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
plammens commentedOct 18, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@tsnoam Before merging I think I should add:
Anything else/any thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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_timestamp
is 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 passNone
toto_float_timestamp()
. - Adding similar capabilities to
from_timestamp()
can be done in a different PR. Lets wrap this one and merge it already ;-)
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
plammens commentedNov 11, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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`. Anexception should be raised at `_put` before an obscure error occurslater down the line.
tsnoam commentedNov 15, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@plammens |
I don't know why pre-commit test failed. On my machine it passes successfully. |
Closes#1505.