title: How to Convert TZInfo identifier to Rails TimeZone name/key
body: <p><strong>How do you convert js values received as TZInfo identifiers to Rails TimeZone name/key?</strong></p>
  
  <p><strong>FROM: <code>"America/New_York"</code> returned from JavaScript TZinfo detection</strong>
  <br><strong>TO: <code>"Eastern Time (US &amp; Canada)"</code> convention used in Rails TimeZone</strong></p>
  
  <p><br>or another example:<br>
  <code>"Pacific/Honolulu"</code> => converted to => <code>"Hawaii"</code></p>
  
  <p>Both are available in <code>ActiveSupport::TimeZone &lt; Object</code> mapping but rails uses the key [i.g.  <code>"Eastern Time (US &amp; Canada)"</code>] in drop-downs, validation &amp; storing to <code>Time.use_zone()</code>.</p>
  
  <h2><br></h2>
  
  <p>Based on what I understand of <code>ActiveSupport::TimeZone.us_zones</code> this seems to be important especially incases of DayLights savings time (which rails sounds to handle well) and matching just the offset would not accomplish.  If it is not stored to DB with the rails TimeZone name then validation fails and does not match up properly in the user's profile settings page with the dropdown list of <code>ActiveSupport::TimeZone.zones_map</code></p>
  
  <p>Goal of this is that the user does not have to select their timezone on signup or are required to change it in their settings after signup.  The browser detects it and passes it to hidden_field on signup.  In the rare occasion they sign up in a place different than their home/work. they can manually override in their account settings later.</p>
  
  <p>Seems to be a common gap when trying to ingest js timezone detection.  This might even become a secondary question of how to pass the returned info from js to rails for conversion and then back to js to store back in the hidden_field of the form?  Hopefully I framed the question properly &amp; admittedly a bit green with rails so there may be a simple solution to this...</p>
  
  <p>Thanks so much for all the help! <br>
  -E</p>
  
  <hr>
  
  <p>ActiveSupport Time.zone Documentation
  <br> <a href="http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html#method-i-parse">http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html#method-i-parse</a></p>
  
  <pre><code>MAPPING = {"Eastern Time (US &amp; Canada)" =&gt; "America/New_York"
  </code></pre>
  
  <p><br>
  Using js packaged gem 'temporal-rails' to detect users timezone: 
  <br> <a href="https://github.com/jejacks0n/temporal">https://github.com/jejacks0n/temporal</a></p>
  
  <p>User Time_Zone implement as seen: 
  <br> <a href="http://railscasts.com/episodes/106-time-zones-revised">http://railscasts.com/episodes/106-time-zones-revised</a></p>
  
  <p>*Using Devise &amp; Devise-Inevitable</p>
  
  <hr>
  
  <h3>Sign-Up View Script</h3>
  
  <pre><code>    &lt;script&gt;
      $(function() {
          var detected_zone = Temporal.detect();
          console.log(detected_zone);  // returns object
          detected_zone = detected_zone.timezone.name;
          console.log(detected_zone);  // returns "America/New_York"
          $('#user_time_zone').val(detected_zone);  // ! need to convert this to rails TimeZone name !
      });
      &lt;/script&gt;
  </code></pre>
  
  <h3>User Model</h3>
  
  <pre><code>    validates_inclusion_of :time_zone, in: ActiveSupport::TimeZone.zones_map(&amp;:name)
  </code></pre>
  
  <h3>User Account Settings Form</h3>
  
  <pre><code>    &lt;%= f.label :time_zone, label: "Time Zone" %&gt;&lt;br /&gt;
      &lt;%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones %&gt;
  </code></pre>