I've (independently) written almost exactly that code! I'm glad my
Ruby skills are finally getting there.
The problem is that each country only appears to contain a single
entry for each timezone. What ends up missing is the US/Eastern
entries, which are redundant.
I suspect that I'll end up tweaking this by hand for the countries
that are wide enough to have many time zones.
Based on this:
(TZInfo::Country.all.map() { |c|[c.name, c.zones.size]}).delete_if {|z| z[1]<4}
Only about 13 countries have more than 4 timezones:
[["Indonesia", 4],
["China", 5],
["Mexico", 8],
["Ukraine", 4],
["Brazil", 15],
["Russia", 15],
["United States", 25],
["Kazakhstan", 5],
["Antarctica", 10],
["Argentina", 10],
["Greenland", 4],
["Australia", 11],
["Canada", 26]]
And, let's face it, only about 6 of those have >10 and are really an issue.
Thanks again!
Sanjay
On 10/23/07, Philip Ross <[EMAIL PROTECTED]> wrote:
> On 23/10/2007, Sanjay Vakil <[EMAIL PROTECTED]> wrote:
> > > There is no link from a timezone to the country or countries that use
> > > it. You could use the information available through the Country class
> > > to build such an index though.
> >
> > This is the bit I couldn't figure out. Could you elucidate?
>
> The following code will give you a hash mapping timezone identifiers
> to the country that uses that timezone.
>
> TZInfo::Country.all.inject({}) do |zones,country|
> country.zone_identifiers.each {|zone_id| zones[zone_id] = country}
> zones
> end
>
> The hash won't contain every timezone - just those that are defined as
> part of a country.
>
> Phil
>
> --
> Phil Ross
> http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
> _______________________________________________
> TZInfo-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/tzinfo-users
>
--
The world tends to work out for me. I try to give it reason to.
_______________________________________________
TZInfo-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/tzinfo-users