From ccaaa720b925f6f05e7f5f47c51a4bbda951f244 Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Thu, 3 Feb 2011 20:36:54 -0800 Subject: [PATCH] Change Time.zone= docs. Update the example to show how to reset the current thread's Time.zone upon exiting a request. --- .../lib/active_support/core_ext/time/zones.rb | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index ef401a6..70b4460 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 TimeZone: # # 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) -- 1.6.2.2