Skip to content

Instantly share code, notes, and snippets.

@normancapule
Last active October 14, 2015 11:27
Show Gist options
  • Save normancapule/50b21f1e4236f9929b21 to your computer and use it in GitHub Desktop.
Save normancapule/50b21f1e4236f9929b21 to your computer and use it in GitHub Desktop.
How we deal with TIMEZONES!
1. User.timezone comes from momentjs moment().format("Z")
2. Everytime user logs in, we pass the browser's timezone
3. Session controller updates user timezone
module TimezoneHelper
def to_timezone(datetime, user)
datetime.in_time_zone(get_timezone_name(user).name)
end
def get_timezone_name(user)
if user.timezone.blank? or user.timezone == "00:00"
ActiveSupport::TimeZone.all.select{|me| me.now.formatted_offset == "-04:00"}.first
else
ActiveSupport::TimeZone.all.select{|me| me.now.formatted_offset == user.timezone}.first
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment