[TZInfo-users] more generic names?

Sanjay Vakil svakil at gmail.com
Tue Oct 23 07:44:53 EDT 2007

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!

On 10/23/07, Philip Ross <phil.ross at gmail.com> wrote:
> On 23/10/2007, Sanjay Vakil <svakil at gmail.com> 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
> TZInfo-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/tzinfo-users

The world tends to work out for me.  I try to give it reason to.

More information about the TZInfo-users mailing list