Changing from UTC offset to time zone identifier in Rails

pRails uses a href="http://rubydoc.info/docs/rails/ActiveSupport/TimeZone"friendly identifiers/a like #8220;Newfoundland#8221; for time zones. It maps multiple identifiers to each UTC offset: for example, #8220;Paris#8221;, #8220;Amsterdam#8221; and #8220;Berlin#8221; all have a UTC offset of 1. If you use a a href="http://rubydoc.info/docs/rails/3.0.0/ActionView/Helpers/FormOptionsHelper:time_zone_select"time_zone_select/a in a form, it will store the selected identifier in the database as a string./p

pWhen users register for my site using Facebook#8217;s a href="http://developers.facebook.com/docs/reference/plugins/login"login button/a, I get the new users#8217; time zones from Facebook, which is expressed as a number (a UTC offset). I need to map these offsets back to Rails#8217; friendly identifiers in order to store time zones in the database in a format that is compatible with tttime_zone_select/tt./p

pTo do that, I map UTC offsets to the friendly identifier that corresponds to the most populous region: for example, I map the UTC offset of 1 to #8220;Paris#8221; and not #8220;Amsterdam#8221;, because Paris is more populous than Amsterdam. If you are expecting more users from less populous regions for some reason, you may want to tweak the following./p

p class="gist"a href="http://gist.github.com/765969"http://gist.github.com/765969/a/p

pNote: I don#8217;t know if Facebook#8217;s UTC offsets change with Daylight Savings Time. The code assumes UTC offsets are given for standard time, as in Rails./pimg src="http://feeds.feedburner.com/~r/slashpoundbang/RQTZ/~4/l30H4IEf8Jc" height="1" width="1"/