Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change Time.zone= docs.

Update the example to show how to reset the current thread's
Time.zone upon exiting a request.
  • Loading branch information...
commit 3a29bfae2cbb956e469942ed1d4ea8c702085a1a 1 parent ac15647
Brian Morearty authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 activesupport/lib/active_support/core_ext/time/zones.rb
View
12 activesupport/lib/active_support/core_ext/time/zones.rb
@@ -19,14 +19,18 @@ def zone
# * A TZInfo::Timezone object.
# * An identifier for a TZInfo::Timezone object (e.g., "America/New_York").
#
- # Here's an example of how you might set <tt>Time.zone</tt> on a per request basis -- <tt>current_user.time_zone</tt>
- # just needs to return a string identifying the user's preferred TimeZone:
+ # Here's an example of how you might set <tt>Time.zone</tt> on a per request basis and reset it when the request is done.
+ # <tt>current_user.time_zone</tt> just needs to return a string identifying the user's preferred time zone:
#
# class ApplicationController < ActionController::Base
- # before_filter :set_time_zone
+ # around_filter :set_time_zone
#
# def set_time_zone
- # Time.zone = current_user.time_zone
+ # old_time_zone = Time.zone
+ # Time.zone = current_user.time_zone if logged_in?
+ # yield
+ # ensure
+ # Time.zone = old_time_zone
# end
# end
def zone=(time_zone)
Please sign in to comment.
Something went wrong with that request. Please try again.