title: Rails: how to create Time object in specific time zone
body: <p>My app is working in "Moscow" (+04:00) timezone. But sometimes I need to create time object by only local time (for example "01 may 2012 13:45") and name of ActiveSupport::TimeZone object (for example "Berlin": +02:00 in Summer Time and +01:00 otherwise).</p>
  
  <p>For example if I get "01 may 2012 13:45" and "Berlin" as input I want to yield "2012-05-01 13:45:00 +0200" or "2012-05-01 11:45:00 +0000". I create following function:</p>
  
  <pre><code>def from_local_datetime(local_datetime, time_zone)
    offset = Time.now.in_time_zone(time_zone).formatted_offset
    datetime = case local_datetime
    when String
      DateTime.parse(local_datetime)
    else
      DateTime.new(local_datetime)
    end.change(:offset =&gt; offset)
  
    return datetime
  end
  </code></pre>
  
  <p>And at the first look it works as I expected. But is it a best practice for this kind of task? May be in some situation It works with errors. I'm not definitely sure.</p>
  
  <p>I would be greatful to any comments.</p>
  
  <p><strong>UPD:</strong> I think bug may occur about time when DST changing the time. For example 26 march 2011 was GMT+1 in Berlin time zone and <code>Time.now.in_time_zone("Berlin").formatted_offset</code> returns "GMT+1", but it would be GMT+2 in 27 march 2011. So if I call <code>from_local_datetime("28 march 2011", "Berlin")</code> before 27 march it returns <code>28 march 2011 00:00:00 +0100</code>, but If I call it after changing the time my function returns <code>28 march 2011 00:00:00 +0200</code> :(</p>