From 3a29bfae2cbb956e469942ed1d4ea8c702085a1a Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Fri, 4 Feb 2011 09:10:07 -0800 Subject: Change Time.zone= docs. Update the example to show how to reset the current thread's Time.zone upon exiting a request. --- activesupport/lib/active_support/core_ext/time/zones.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/time/zones.rb') diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index ef401a6d18..ff90d7ca58 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -19,14 +19,18 @@ class Time # * 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 Time.zone on a per request basis -- current_user.time_zone - # just needs to return a string identifying the user's preferred TimeZone: + # Here's an example of how you might set Time.zone on a per request basis and reset it when the request is done. + # current_user.time_zone 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) -- cgit v1.2.3