Last active
October 14, 2015 11:27
-
-
Save normancapule/50b21f1e4236f9929b21 to your computer and use it in GitHub Desktop.
How we deal with TIMEZONES!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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