views:

268

answers:

3

I'm wondering if there is an easy way to look up a user's local time zone in Rails using only an IP address. I don't want users to have to input their time zone themselves. Do I have to use JavaScript or is there a different way?

+1  A: 

There appear to be several vendors offering APIs and callable services to go from ip address to location, and clearly once you have that determining the timezone is only a further lookup.

Your alternative of using javascript to ask the browser "where am I, what's the time zone" and Ajaxing that down to your server also sounds plausible.

Of course a sufficiently determined user can probably spoof their way to appearing to be at a different ip address, but presumably that doesn't matter too much to you ... their choice.

djna
+1  A: 

The maxmind GeoLite IP->city database seems to support timezones and there's a FAQ on their site referring to this. You could either do a two-step process of IP->Location then Location->timezone using the Maxmind GeoLite City database and then use one of the solutions provided in the FAQ.

Or for a simple 1-step javascript, using getTimezoneOffset() seems to be the crux of the solution.

hopeless
+1  A: 

Hi Alex, you can use the ip address-to-time API to find time by IP address. Look here http://worldtimeengine.com/ for more details.

Dan