require ‘rubygems’
require ‘hpricot’
require ‘active_support’
require ‘active_support/time_with_zone’
require ‘open-uri’
require ‘net/http’

class TimeZoneFinder
def self.find_gmt_offset(lat,lng)
uri = URI.parse(“http://ws.geonames.org/timezone?lat=#{lat}&lng=#{lng}”)
doc = Hpricot.XML(Net::HTTP.get(uri))
(doc/”geonames”/”timezone”/”gmtOffset”).innerHTML.to_f
end
end

offset = TimeZoneFinder.find_gmt_offset(“39.0″,”-86.0″)
puts timezone = ActiveSupport::TimeZone[offset]

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s