Skip to content

Conversation

@roback
Copy link
Member

@roback roback commented Feb 23, 2016

  • Query#start_time and #end_time are converted to UTC before making the request.
  • Post#published and #indexed has their timezone set to UTC.

close #16

Todo

  • test that use dateutil (to show that that works/is supported) (98bcf5e)
  • show in examples that you can use pytz or dateutil (cdecac5)

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.
q = self._client.query()
q.pattern = "spotify"
q.start_time = datetime(2012, 12, 28, 9, 1, 22)
with self.assertRaises(twingly_search.TwinglyQueryException):
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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).

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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

Copy link
Member Author

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 13bef57

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dentarg
Copy link
Contributor

dentarg commented Feb 23, 2016

What we talked about during fika:

  • test that use dateutil (to show that that works/is supported)
  • show in examples that you can use pytz or dateutil

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.
@roback
Copy link
Member Author

roback commented Feb 24, 2016

show in examples that you can use pytz or dateutil

The examples I added only uses dateutil (I went with dateutil because I wanted to use its parse() function).

@dentarg
Copy link
Contributor

dentarg commented Feb 24, 2016

LGTM :)

dentarg added a commit that referenced this pull request Feb 24, 2016
Convert datetimes to UTC
@dentarg dentarg merged commit 4179873 into master Feb 24, 2016
@dentarg dentarg deleted the utc branch February 24, 2016 15:21
roback added a commit that referenced this pull request Mar 3, 2016
* If Query#start_time and #end_time contains timezone information,
  convert it to UTC (#21)
* Parse post tags correctly (#19)
* Minor documentation improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert query start and end time to UTC

4 participants