Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Last active December 14, 2015 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwoertink/5035116 to your computer and use it in GitHub Desktop.
Save jwoertink/5035116 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment