Timezone offset with date parameters

631 views
Skip to first unread message

J

unread,
Nov 11, 2011, 7:03:07 PM11/11/11
to shopi...@googlegroups.com
To retrieve updated orders, we are using the "updated_at_min" param for the Order API (http://api.shopify.com/order.html).  The specified format in the docs (e.g. 2008-01-01 03:00) doesn't include a timezone offset from UTC.  Based on our testing, we see that the date is expected to be in the timezone of the shop.

Questions:
  1. Do we call the Shop API (http://api.shopify.com/shop.html) in order to find the shop's timezone?
  2. Can the shop owner change this timezone?  If so, how would we know so that we could continue to make the Order API call with the correct timezone? Continuous polling?
  3. How is daylight savings time handled?  Would the Shop API call return a different timezone in the winter vs summer?  
  4. For dates returned in the order response (e.g. "created_at": "2008-01-10T11:00:00-05:00"), do the timezone offsets change for the EXACT SAME order (including past orders) due to changes mentioned in #2 and #3 (i.e. if the user changes their timezone or DST).
Is it possible to include the timezone offset for "updated_at_min" (as well as any other date params)?  I believe this would eliminate all ambiguities listed in the questions above.

Thanks,
J

J

unread,
Nov 14, 2011, 1:27:32 PM11/14/11
to shopi...@googlegroups.com
Can anyone from Shopify clarify my questions in regards to timezone offsets?

David Underwood

unread,
Nov 14, 2011, 2:00:33 PM11/14/11
to shopi...@googlegroups.com
Hi J,
  1. You can provide specific timezones on your parameters and the API will take them into account when searching for orders
  2. Store owners can change their timezone, but as long as you specify one on your parameters that shouldn't matter
  3. If the store owner changes their timezone (or DST occurs), times provided through the API are updated accordingly. They'll still correspond to the same UTC time. Here's an example I just tested:
Before (On Alaska Time):
<created-at type="datetime">2011-11-08T11:45:35-09:00</created-at>

After (On Eastern Time):
<created-at type="datetime">2011-11-08T15:45:35-05:00</created-at>


Hope that helps. Let us know if you have any more issues. Thanks!

-David Underwood
 Developer Advocate, Shopify

J

unread,
Nov 14, 2011, 2:10:34 PM11/14/11
to shopi...@googlegroups.com
Awesome, what's the date format expected for dates with timezones?  I tried "2011-11-14T19:08:30+0000" but that didn't seem to work.

David Underwood

unread,
Nov 14, 2011, 3:38:06 PM11/14/11
to shopi...@googlegroups.com
It's the same as the format we give back to you in responses, so that date would need to look like this:

2011-11-14T19:08:30+00:00

-David Underwood
 Developer Advocate, Shopify

J

unread,
Nov 14, 2011, 4:10:43 PM11/14/11
to shopi...@googlegroups.com
Ah, looks like the missing colon is the issue.  Thanks!

Before I got your response, I noticed that the api doc (http://api.shopify.com/order.html) had this example:

GET /admin/orders.json?updated_at_min=2005-07-31 15:57:11 EDT -04:00

I tested this and it seems to work.  I guess this format as well as the one you mentioned both work?


David Underwood

unread,
Nov 14, 2011, 4:13:48 PM11/14/11
to shopi...@googlegroups.com
Yup. The date parser will accept either of those.

Edward Ocampo-Gooding

unread,
Nov 14, 2011, 4:14:49 PM11/14/11
to shopi...@googlegroups.com
Yep. Internally, we’re doing a `where(["updated_at >= ?", params[:updated_at_min] ])` as part of an Active Relation call.

As long as the string you give us makes sense to the ARel sanitizer + timestamp serializer in the db adapter (which is pretty forgiving), you’ll be ok.

(I usually just work with timestamps as given to me via Ruby’s time and date classes.)

Edward Ocampo-Gooding
Developer Advocate, Shopify

Edward Ocampo-Gooding

unread,
Nov 14, 2011, 4:15:42 PM11/14/11
to shopi...@googlegroups.com
Lol at the double Dev Advocate reply. Man, we’re starting to sound and write the same...

J

unread,
Dec 10, 2011, 5:41:04 PM12/10/11
to shopi...@googlegroups.com
Looks like the timezone offset is not being respected when using the "updated_at_min" parameter for Orders API (http://api.shopify.com/order.html).

Example:

Response:

{"orders":[{"created_at":"2011-12-11T09:22:33+11:00","updated_at":"2011-12-11T09:25:54+11:00"},{"created_at":"2011-12-11T09:22:29+11:00","updated_at":"2011-12-11T09:23:28+11:00"},{"created_at":"2011-12-11T08:34:30+11:00","updated_at":"2011-12-11T08:35:43+11:00"},{"created_at":"2011-12-11T07:24:39+11:00","updated_at":"2011-12-11T07:27:06+11:00"},{"created_at":"2011-12-11T06:58:20+11:00","updated_at":"2011-12-11T07:00:25+11:00"},{"created_at":"2011-12-11T04:00:16+11:00","updated_at":"2011-12-11T04:01:20+11:00"},{"created_at":"2011-12-11T03:58:11+11:00","updated_at":"2011-12-11T03:59:29+11:00"},{"created_at":"2011-12-11T00:54:04+11:00","updated_at":"2011-12-11T00:55:54+11:00"},{"created_at":"2011-12-11T00:32:09+11:00","updated_at":"2011-12-11T00:35:47+11:00"},{"created_at":"2011-12-11T00:29:20+11:00","updated_at":"2011-12-11T00:30:33+11:00"}]}

As you can see, the results are returned not respecting the "+00:00" timezone offset.  Instead it appears to be querying based on local time of "+11:00".

Is this a bug?

-J

Edward Ocampo-Gooding

unread,
Dec 13, 2011, 2:47:02 PM12/13/11
to shopi...@googlegroups.com
Hey Jamie,

The filter is working correctly, but the response will always be in the shop‘s own timezone.

Here’s an example of me messing around in the Ruby console that shows me playing around with the timezones and the filter doing the right thing:

irb(main):009:0> Order.find(:all, :params => {:created_at_min => '2011-11-29T15:51:30+00:00'}).map(&:created_at)
=> ["2011-11-29T15:51:30-05:00"]
irb(main):010:0> Order.find(:all, :params => {:created_at_min => '2011-11-29T15:51:30-05:00'}).map(&:created_at)
=> ["2011-11-29T15:51:30-05:00"]
irb(main):011:0> Order.find(:all, :params => {:created_at_min => '2011-12-29T15:51:30-05:00'}).map(&:created_at)
=> []
irb(main):012:0> Order.find(:all, :params => {:created_at_min => '2011-11-29T15:51:31-05:00'}).map(&:created_at)
=> []
irb(main):013:0> Order.find(:all, :params => {:created_at_min => '2011-11-29T15:51:31-04:00'}).map(&:created_at)
=> ["2011-11-29T15:51:30-05:00"]

Jamie Tsao

unread,
Dec 13, 2011, 4:32:31 PM12/13/11
to shopi...@googlegroups.com
It works fine for "created_at_min", but doesn't for "updated_at_min".  

Edward Ocampo-Gooding

unread,
Dec 13, 2011, 5:22:08 PM12/13/11
to shopi...@googlegroups.com
Here’s me doing the same thing with updated_at – it looks like it’s working correctly.

irb(main):007:0> Order.find(:all, :params => {:updated_at_min => '2011-11-29T15:51:30-06:00'}).map(&:updated_at)
=> []
irb(main):008:0> Order.find(:all, :params => {:updated_at_min => '2011-11-29T15:51:30-05:00'}).map(&:updated_at)
=> ["2011-11-29T15:51:50-05:00"]
irb(main):009:0> Order.find(:all, :params => {:updated_at_min => '2011-11-29T15:51:30-04:00'}).map(&:updated_at)
=> ["2011-11-29T15:51:50-05:00"]

Might you have a formatting problem?

Edward Ocampo-Gooding
Developer Advocate, Shopify


On Tuesday, 13 December, 2011 at 4:32 PM, Jamie Tsao wrote:

> It works fine for "created_at_min", but doesn't for "updated_at_min".
>

David Underwood

unread,
Dec 15, 2011, 2:04:39 PM12/15/11
to shopi...@googlegroups.com
I took a look at this earlier today, and I think I've figured out what's going on.

Jamie: The examples you posted all have raw '+' characters in the url. These are converted to spaces on the server side and so your timezone isn't being correctly parsed. Try running your params through a url encoder before sending them and you should be good to go.

J

unread,
Dec 15, 2011, 7:46:15 PM12/15/11
to shopi...@googlegroups.com
That was the problem.  Thanks!

Another question: For API calls where I'm querying by "updated_at_min", it is possible to have the results sorted by "updated_at" , instead of "created_at"?

I believe that if there are multiple pages of results, then while I'm processing page 5 (for example), I might miss an order that suddenly appears in page 1 since it's being sorted by "created_at".  Does this make sense?

Let me know what you think and if it's possible to return results sorted by "updated_at".

Thanks again! 

Edward Ocampo-Gooding

unread,
Dec 15, 2011, 8:31:04 PM12/15/11
to shopi...@googlegroups.com
Use since_id to avoid this issue

J

unread,
Dec 16, 2011, 12:24:17 AM12/16/11
to shopi...@googlegroups.com
I'm using "updated_at_min" to regularly poll for orders that have been updated.  In this case, if the results require paging, I believe the potential to miss out on updates can occur given the sorting.

I'm unclear how I would use since_id for this situation where I'm looking for updates.

Reply all
Reply to author
Forward
0 new messages