Skip to content

Instantly share code, notes, and snippets.

@kueda
Created June 20, 2014 21:24
Show Gist options
  • Save kueda/3e6f77f64f792b4f119f to your computer and use it in GitHub Desktop.
Save kueda/3e6f77f64f792b4f119f to your computer and use it in GitHub Desktop.
Took me a while to figure out how to get at all the time zone abbreviations stored within the TZInfo gem. I'm sure there's a better way, but this works.
abbrevs = {}
TZInfo::Timezone.all.each do |tz|
tz = tz.send(:real_timezone) unless tz.class == TZInfo::Timezone
tzi = tz.send(:info)
offsets = tzi.instance_variable_get(:@offsets)
next if offsets.blank?
offsets.values.each do |offset|
abbrevs[offset.abbreviation] ||= []
abbrevs[offset.abbreviation] << tz.identifier
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment