Ok, based on what you said and @dhouty's answer :
You want to be able to feed into the offset and get a set of dates, knowing if there is a DST offset or not. I would recommend getting a range of two DateTime objects as a result, since it is easy to use for many purposes in Rails ...
require 'tzinfo' def make_dst_range(offset) if dst_end = ActiveSupport::TimeZone[offset].tzinfo.current_period.local_end dst_start = ActiveSupport::TimeZone[offset].tzinfo.current_period.local_start dst_range = dst_start..dst_end else dst_range = nil end end
Now you have a method that can do more than just bias thanks to the sugar that comes with ActiveSupport. You can do things like:
make_dst_range(-8)
Today is August 29th, like this:
my_range.cover?(Date.today) #=> true my_range.cover?(Date.today + 70) #=> false my_range.first #=> Sun, 08 Mar 2015 03:00:00 +0000 #note that this is a DateTime object. If you want to print it use: my_range.first.to_s #=> "2015-03-08T03:00:00+00:00" my_range.last.to_s #=> "2015-11-01T02:00:00+00:00"
ActiveSupport provides you with all kinds of goodies to display:
my_range.first.to_formatted_s(:short) #=> "08 Mar 03:00" my_range.first.to_formatted_s(:long) #=> "March 08, 2015 03:00" my_range.first.strftime('%B %d %Y') #=> "March 08 2015"
Since you can see that this is fully feasible with just the offset, but as I said, the offset doesn't tell you everything, so you might want to grab their actual time zone and save it as a string, as the method would happily accept this string and still give you a date range. Even if you just get a temporary offset between your zone and them, you can easily understand that this is a UTC offset:
my_offset = -8 their_offset = -3 utc_offset = my_offset + their_offset
source share