Get UTC timezone offset where hour is X in ruby
<p>I have a cronjob running and every time the task is run I want to load contacts from my database where the local hour for that individual is the specified hour in my cron system. </p>

<p>For example: give me all contacts in the timezone where it is current the 4pm hour (16th hour). </p>

<p>In order to accomplish this, I want to make a simple function that returns the <a href="https://en.wikipedia.org/wiki/List_of_UTC_time_offsets" rel="nofollow">UTC timezone offset</a> where the current hour is X. </p>

<p>This is the best solution I came up with but figure there's something more efficient.</p>

<pre><code>def timezone_offset_for_hour hour
    ["-12:00","-11:00","-10:00", "-09:30","-09:00","-08:00","-07:00","-06:00","-05:00","-04:00","-03:30",
"-03:00","-02:00","-01:00","+00:00","+01:00","+02:00","+03:00","+03:30","+04:00","+04:30","+05:00","+05:30",
"+05:45","+06:00","+06:30","+07:00","+08:00","+08:30","+08:45","+09:00","+09:30","+10:00","+10:30",
"+11:00","+12:00","+12:45","+13:00","+14:00"].select{ |o| Time.now.getlocal(o).hour == hour }
end
</code></pre>

<p>The solution can be pure ruby or include Rails methods.</p>