Correlate time zone abbreviations with time zone names by jgn on Monday, November 7, 2011 in Ruby and Code

There has got to be any easier way.

require 'rubygems'
require 'tzinfo'
require 'active_support'
require 'active_support/values/time_zone'


time_zone_names = ['Eastern Time (US & Canada)', 'Central Time (US & Canada)', 'Paris']
abbrev_to_zone = time_zone_names.inject({}) do |map, name|
  map[ActiveSupport::TimeZone.find_tzinfo(name).current_period.abbreviation.to_s] = name; map
end


p Time.now.zone
p abbrev_to_zone[Time.now.zone]
p abbrev_to_zone['CET']
comments powered by Disqus