public
Last active

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
# Need a method that takes a date and based on a given time zone gives me the correct offset
# with daylight savings time into consideration
Time.zone = "Pacific US and Canada"
 
Time.some_method_name("2013-03-09") #=> "PST -0800"
Time.some_method_name("2013-03-10") #=> "PDT -0700"
 
#############
 
ActiveSupport::TimeZone.all.sort_by(&:name).each_with_index do |timezone, index|
# Need this to be "-0700 Pcific Time (US & Canada) if a specified date is after DST
"#{timezone.formatted_offset(false)} #{timezone.name}" # => "-0800 Pacific Time (US & Canada)"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.