From svakil at gmail.com Mon Oct 22 16:13:42 2007 From: svakil at gmail.com (Sanjay Vakil) Date: Mon, 22 Oct 2007 16:13:42 -0400 Subject: [TZInfo-users] more generic names? Message-ID: Hiya! TZInfo is back in my life, and that's quite nice. What I'd like to do is to show the "simpler" names of timezones, rather than the city name: EST instead of America/New_York PST instead of America/Los_Angeles Is there a way to derive this? I looked at linked_zones, thinking I could use those, but they don't appear to link back to the country in question, or the zone that they link to. At minimum, from a UI standpoint, it'd be nice to show something like: EST - New York Thanks, Sanjay -- The world tends to work out for me. I try to give it reason to. From svakil at gmail.com Mon Oct 22 16:17:52 2007 From: svakil at gmail.com (Sanjay Vakil) Date: Mon, 22 Oct 2007 16:17:52 -0400 Subject: [TZInfo-users] population numbers? Message-ID: Hiya. In the docs, it talks about a given country's list of TZs being organized geographically, and then by population. Is the population data available? Could it be made so? Here's why: I'm using javascript to get a UTC offset. And then using that offset, along with the country that the user's selected, to attempted to guess at the correct timezone. The code only has one axis to work on -- how close the offset is. As such, it automatically grabs the very first entry that matches. In the case of Canada, a GMT-4 shows us as "Blanc-Sablon" rather than, say, Montreal or Toronto. If the population data were to be available, I'd use that to sort all of the matches and choose the most populous one. Thanks, sanjay -- The world tends to work out for me. I try to give it reason to. From svakil at gmail.com Mon Oct 22 16:20:50 2007 From: svakil at gmail.com (Sanjay Vakil) Date: Mon, 22 Oct 2007 16:20:50 -0400 Subject: [TZInfo-users] one more... Message-ID: It appears, in looking at the zone data, that there are multiple "city" entries in what much of the world considers a single timezone. I'm assuming this is for historical reasons -- Detroit and New York were not always in the same timezone. Is there a way to get a list of just those timezones which are actually different going forward? I guess this relates back to my earlier question about showing PST/EST/MST/CST. sanj -- The world tends to work out for me. I try to give it reason to. From phil.ross at gmail.com Mon Oct 22 18:15:56 2007 From: phil.ross at gmail.com (Philip Ross) Date: Mon, 22 Oct 2007 23:15:56 +0100 Subject: [TZInfo-users] more generic names? In-Reply-To: References: Message-ID: <4ac540410710221515o5cd2eb37u6ea6e3b377ec1f87@mail.gmail.com> On 22/10/2007, Sanjay Vakil wrote: > What I'd like to do is to show the "simpler" names of timezones, > rather than the city name: > > EST instead of America/New_York > PST instead of America/Los_Angeles > > Is there a way to derive this? > > I looked at linked_zones, thinking I could use those, but they don't > appear to link back to the country in question, or the zone that they > link to. Linked timezones are just aliases to other zones. TZInfo hides the details of the linked timezone. 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. > At minimum, from a UI standpoint, it'd be nice to show something like: > > EST - New York If you are interested in seeing EST/EDT, etc, then you can obtain a TimezonePeriod object using Timezone#current_period, Timezone#period_for_utc or Timezone#period_for_local and call its abbreviation method. The New York part can be obtained by calling Timezone#friendly_identifier(true) Phil -- Phil Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby From phil.ross at gmail.com Mon Oct 22 18:16:34 2007 From: phil.ross at gmail.com (Philip Ross) Date: Mon, 22 Oct 2007 23:16:34 +0100 Subject: [TZInfo-users] population numbers? In-Reply-To: References: Message-ID: <4ac540410710221516o42675410yecb00ffa2c4d43df@mail.gmail.com> On 22/10/2007, Sanjay Vakil wrote: > Hiya. > > In the docs, it talks about a given country's list of TZs being > organized geographically, and then by population. > > Is the population data available? Could it be made so? TZInfo uses data from the tz database (http://www.twinsun.com/tz/tz-link.htm) and this is where that statement is taken from. I don't have the population data. It isn't available in machine readable format in the tz database. You could try asking on the tz mailing list (referenced in the link above) to see if anyone has done anything involving population data and timezones before. > Here's why: > > I'm using javascript to get a UTC offset. And then using that offset, > along with the country that the user's selected, to attempted to guess > at the correct timezone. The code only has one axis to work on -- how > close the offset is. Other people I've spoken to about doing similar things have tended to go for a bit of manual tweaking to pick representative zones for the larger countries. Phil -- Phil Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby From phil.ross at gmail.com Mon Oct 22 18:17:46 2007 From: phil.ross at gmail.com (Philip Ross) Date: Mon, 22 Oct 2007 23:17:46 +0100 Subject: [TZInfo-users] one more... In-Reply-To: References: Message-ID: <4ac540410710221517p6ce9b9bfp753421d9f2a09@mail.gmail.com> On 22/10/2007, Sanjay Vakil wrote: > It appears, in looking at the zone data, that there are multiple > "city" entries in what much of the world considers a single timezone. > > I'm assuming this is for historical reasons -- Detroit and New York > were not always in the same timezone. Yes, your assumption is correct. Detroit and New York have been different in the past, but since 27 April 1975 have used identical rules. The source tz database (http://www.twinsun.com/tz/tz-link.htm) lists all the timezones available for each country rather than just those with different current and future rules. > Is there a way to get a list of just those timezones which are > actually different going forward? There isn't a simple way to do this with TZInfo - you'd have to compare each future TimezonePeriod for each pair of Timezones to determine if they were the same. If they were the same, you'd need a rule of some sort to determine which zone you will use, so this might require some manual intervention. > I guess this relates back to my earlier question about showing PST/EST/MST/CST. For the US, there are a set of linked timezones defining the distinct set of rules that are in force. These are: US\Alaska US\Aleutian US\Arizona US\Central US\East - Indiana US\Eastern US\Hawaii US\Indiana - Starke US\Michigan US\Mountain US\Pacific US\Samoa Phil -- Phil Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby From svakil at gmail.com Mon Oct 22 20:03:06 2007 From: svakil at gmail.com (Sanjay Vakil) Date: Mon, 22 Oct 2007 20:03:06 -0400 Subject: [TZInfo-users] more generic names? In-Reply-To: <4ac540410710221515o5cd2eb37u6ea6e3b377ec1f87@mail.gmail.com> References: <4ac540410710221515o5cd2eb37u6ea6e3b377ec1f87@mail.gmail.com> Message-ID: > 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? thanks, sanj On 10/22/07, Philip Ross wrote: > On 22/10/2007, Sanjay Vakil wrote: > > What I'd like to do is to show the "simpler" names of timezones, > > rather than the city name: > > > > EST instead of America/New_York > > PST instead of America/Los_Angeles > > > > Is there a way to derive this? > > > > I looked at linked_zones, thinking I could use those, but they don't > > appear to link back to the country in question, or the zone that they > > link to. > > Linked timezones are just aliases to other zones. TZInfo hides the > details of the linked timezone. > > 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. > > > At minimum, from a UI standpoint, it'd be nice to show something like: > > > > EST - New York > > If you are interested in seeing EST/EDT, etc, then you can obtain a > TimezonePeriod object using Timezone#current_period, > Timezone#period_for_utc or Timezone#period_for_local and call its > abbreviation method. > > The New York part can be obtained by calling Timezone#friendly_identifier(true) > > 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. From phil.ross at gmail.com Tue Oct 23 05:32:00 2007 From: phil.ross at gmail.com (Philip Ross) Date: Tue, 23 Oct 2007 10:32:00 +0100 Subject: [TZInfo-users] more generic names? In-Reply-To: References: <4ac540410710221515o5cd2eb37u6ea6e3b377ec1f87@mail.gmail.com> Message-ID: <4ac540410710230232lf149dbbt8b24862ecafd9b60@mail.gmail.com> On 23/10/2007, Sanjay Vakil 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 From svakil at gmail.com Tue Oct 23 07:44:53 2007 From: svakil at gmail.com (Sanjay Vakil) Date: Tue, 23 Oct 2007 07:44:53 -0400 Subject: [TZInfo-users] more generic names? In-Reply-To: <4ac540410710230232lf149dbbt8b24862ecafd9b60@mail.gmail.com> References: <4ac540410710221515o5cd2eb37u6ea6e3b377ec1f87@mail.gmail.com> <4ac540410710230232lf149dbbt8b24862ecafd9b60@mail.gmail.com> Message-ID: 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 wrote: > On 23/10/2007, Sanjay Vakil 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.