-
Notifications
You must be signed in to change notification settings - Fork 1
Convert datetimes to UTC #21
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
The methods Query#_ts and Query#_tsTo were almost the same. Also, _tsTo used camelcase which is another reason I wanted to get rid if it :)
Query#start_time and #end_time requires the user of the gem to set timezone, we should set it ourselves too.
Self can not be accessed outside functions so the defaults has to be set in a constructor. This change also fixes the following bug: The attributes declared outside of the constructor, as they were before, resulted in the attributes beeing set on the class and not the instance.
tests/test_query.py
Outdated
| q = self._client.query() | ||
| q.pattern = "spotify" | ||
| q.start_time = datetime(2012, 12, 28, 9, 1, 22) | ||
| with self.assertRaises(twingly_search.TwinglyQueryException): |
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.
Maybe you've talked about this already, but if no timezone given I think we should assume UTC rather than raising.
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.
I said we should raise: #16 (comment)
but in the next comment I started to doubt myself... so it's still open for discussion
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.
Ah, thought I had seen it somewhere. Anyway, what does our other libraries do? I was under the impression we don't raise, but I haven't closely followed the latest changes and I can't test now.
To me, at least, it makes sense to assume no tzinfo => UTC.
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.
It's different for Ruby and Node.js, because they default to your local timezone, so we always have that information. We haven't done PHP yet, but PHP will yell at you if you don't configure your timezone or explicitly pick one when creating the date object (as we do in our examples).
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.
Since the standard library has no support for timezones I think we could just assume its UTC. Right now the user is required to add pytz/dateutil (or something similar) to be able to use the client.
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.
Sounds reasonable.
We can have something about it in the README.
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.
Made some changes in 868a5c8
| @@ -1,2 +1,3 @@ | |||
| future | |||
| requests | |||
| pytz | |||
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.
we also list requirements in the README, but don't I think we need to do that when we have this file
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.
Yes, I think that requests should be removed from the readme instead :)
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.
Done in 13bef57
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.
👍
|
What we talked about during fika:
|
There are two popular date-time related packages in python; pytz and dateutil. Now we have query tests for both of them.
An example explaining how twingly_search handles timezones.
The examples I added only uses dateutil (I went with dateutil because I wanted to use its |
|
LGTM :) |
Query#start_timeand#end_timeare converted to UTC before making the request.Post#publishedand#indexedhas their timezone set to UTC.close #16
Todo