[TZInfo-users] finding equivalent time zones

David Byron dbyron at dbyron.com
Mon Feb 25 17:34:32 UTC 2013


Picking up an old thread 
(http://rubyforge.org/pipermail/tzinfo-users/2007-October/000021.html, 
apologies for not setting in-reply-to properly), I had an idea for 
finding equivalent time zones.  I was all ready to go off and implement 
it, but now that tzinfo-data is separate there are more moving parts so 
I figured I'd ask first to see if this has a chance of being accepted 
upstream.

My goal is to end up with class method on TZInfo::Timezone something 
like this:

def self.map_equal_zones(zones,since)
end

The return value of this method is a hash with a key for each zone in 
the input zones array.  The value is the primary/master/base zone. 
Still fishing for the right name there.

The idea is that if you pass TZInfo::Timezone::us_zones and a fairly 
recent date, you only get one of these zones as a value.

[#<TZInfo::CountryTimezone: America/New_York>,
  #<TZInfo::CountryTimezone: America/Chicago>,
  #<TZInfo::CountryTimezone: America/Denver>,
  #<TZInfo::CountryTimezone: America/Phoenix>,
  #<TZInfo::CountryTimezone: America/Los_Angeles>,
  #<TZInfo::CountryTimezone: America/Anchorage>,
  #<TZInfo::CountryTimezone: America/Adak>,
  #<TZInfo::CountryTimezone: America/Metlakatla>,
  #<TZInfo::CountryTimezone: Pacific/Honolulu>]

My idea for how to do this is to include observance information from 
data files in DataTimezoneInfo, and then compare observances from the 
given start date (since) to figure out what's equal to what.  It seems 
fairly straightforward to include observance info in 
tzinfo-data/lib/definitions by adjusting TZDataZone to write 
@observances.  From there, it seems similarly straightforward to adjust 
DataTimezoneInfo to provide access to the info.  No need to parse the 
rules that the observances reference as far as I can tell.

The decision of what the primary zone is for a given set of equal zones 
would come from the order of the given zones, which with the return 
value from TZInfo::Timezone::us_zones appears to be based on the order 
in the original data files, which is just right for me.

Thoughts?

-DB


More information about the TZInfo-users mailing list