Skip to content

Instantly share code, notes, and snippets.

@ashchan
Forked from jnunemaker/application.js
Created February 24, 2011 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashchan/841713 to your computer and use it in GitHub Desktop.
Save ashchan/841713 to your computer and use it in GitHub Desktop.
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
class ApplicationController < ActionController::Base
before_filter :set_timezone
# …
private
def set_timezone
if current_user && browser_timezone && browser_timezone.name != current_user.time_zone
current_user.update_attributes :time_zone => browser_timezone.name
end
Time.zone = current_user ? current_user.time_zone : browser_timezone
end
def browser_timezone
@browser_timezone ||= begin
ActiveSupport::TimeZone[-cookies[:tz].to_i.minutes]
end if cookies[:tz].present?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment