I'm trying to determine the timezone of a country (from 2-letter ISO3166 country code) using Ruby. I have tried the Ruby gem tzinfo
I can get the timezones of Brazil this way:
TZInfo::Country.get("BR").zone_identifiers
=> ["America/Noronha", "America/Belem", "America/Fortaleza", "America/Recife", "America/Araguaina", "America/Maceio", "America/Bahia", "America/Sao_Paulo", "America/Campo_Grande", "America/Cuiaba", "America/Santarem", "America/Porto_Velho", "America/Boa_Vista", "America/Manaus", "America/Eirunepe", "America/Rio_Branco"]
Brazil has several timezones. The list above is sorted based on proximity to UTC. In this case, east to west. We want to get the main timezone, by which I mean the timezone where the capital city of the country is located. "America/Noronha" is the timezone of an island in the Atlantic. We want to get the timezone of Brasilia (the capital city of Brazil) in this case.
Based on tzinfo documentation, I can get a list of timezones "ordered by importance according to the DataSource" using class TZInfo::CountryInfo (not sure what DataSource is)
But this doesn't seem to work:
>> x=TZInfo::CountryInfo.new('BR', 'Brazil')
=> #<TZInfo::CountryInfo: BR>
>> x.zones
=> []
>> x.zone_identifiers
=> []
So how do you easily obtain the time zone where a country's capital is located? Are there any gems that support capital city's timezone?
Thank you.