title: Ruby Timezones — to UTC and back
body: <p>I run a scheduling site that allows users to set a timezone for their account. They can then schedule 'posts' on a calendar for that timezone. In the back-end, I take the time and convert it into UTC time (where a worker processes and picks up those posts on UTC time).</p>
  
  <p>I run the site on Ruby (with Puma/Sinatra), but without Rails, and I'd like to stay away from Rails. There's HTML/ERB/JS in the front and a MYSQL backend.</p>
  
  <p>I thought that simply adding/subtracting UTC offsets will solve all problems. I have a simple list that has <code>TIMEZONE &lt;--&gt; UTCOFFSET</code> and this worked very well — or so I thought.</p>
  
  <p>And then I realised this does not work when a given timezone (or place) is in DST currently.</p>
  
  <p><em>Vienna in the summer: UTC offset: +2h</em></p>
  
  <p><em>Vienna in the winter: UTC offset: +1h</em></p>
  
  <p>Is there a simple way to give Ruby (not Rails) a "timezone ID" and receive the correct adjusted UTC offset back? </p>
  
  <p>Like:</p>
  
  <pre><code>user.timezone = "Europe/Vienna"
  utc_adjusted_time = post.local_time.to_i + get_utc_offset(user.timezone)
  </code></pre>
  
  <p>Where <code>get_utc_offset</code> <em>knows</em> whether it is in DST or not. Any ideas?</p>
  
  <p>I've gone through the IANA database (which is absolute overkill), I've searched through numerous Gists on Github, I've tried to abuse whatever Rails seemed to have, but didn't get very far.</p>
  
  <p>How do you guys handle this? Ideally, as said, each post will be converted and saved to a DST-stripped UTC time. Thanks!</p>