/ Published in: Ruby
Expand |
Embed | Plain Text
countries = Country.find(:all) for country in countries begin tzc = TZInfo::Country.get(country.code.upcase) rescue puts "can't find TZInfo for #{country.code.upcase}" next end puts tzc.name for zone in tzc.zone_names puts country.code.upcase puts zone CountryTimeZone.create(:parent_id => country.id, :name => zone) end end
Comments
Subscribe to comments
You need to login to post a comment.

The class TZInfo::Country requires the tzinfo gem and TZInfo plugin (http://tzinfo.rubyforge.org). Country and CountryTimeZone classes are my own (subclassed from my Geography class). This snippet gets the two-letter country code for each country and uses it to find all the time zones for the country and then creates a new CountryTimeZone instance for each, specifying the country as a parent_id so we can do a tree list of countries and their "children" time zones. This snippet is run from the console and populates a data table.