aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2008-02-06 06:43:02 +0000
committerRick Olson <technoweenie@gmail.com>2008-02-06 06:43:02 +0000
commit72385a7be65bb27b07cd2ee3bc9fe221d8e04f90 (patch)
tree24e89ad3c45c6bcd41ddaa0f02d8e4918c28d51d /activesupport/lib
parent692dbbf79387b56e241e1acd05f74f7d71ff79a6 (diff)
downloadrails-72385a7be65bb27b07cd2ee3bc9fe221d8e04f90.tar.gz
rails-72385a7be65bb27b07cd2ee3bc9fe221d8e04f90.tar.bz2
rails-72385a7be65bb27b07cd2ee3bc9fe221d8e04f90.zip
Add Time Zone support to ActiveRecord, and config.time_zone property for specifying a default Time Zone. Closes #10982 [Geoff Buesing, rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8806 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb4
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb8
2 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb
index 7b9106b4ac..33c7800705 100644
--- a/activesupport/lib/active_support/core_ext/time/zones.rb
+++ b/activesupport/lib/active_support/core_ext/time/zones.rb
@@ -9,8 +9,10 @@ module ActiveSupport #:nodoc:
end
module ClassMethods
+ attr_accessor :zone_default
+
def zone
- Thread.current[:time_zone]
+ Thread.current[:time_zone] || zone_default
end
# Sets a global default time zone, separate from the system time zone in ENV['TZ'].
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index d1dba65f86..fed64579e4 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -174,6 +174,14 @@ class TimeZone
def to_s
"(UTC#{formatted_offset}) #{name}"
end
+
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of self. Example:
+ #
+ # Time.zone = "Hawaii" # => "Hawaii"
+ # Time.zone.new(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
+ def new(*args)
+ Time.utc_time(*args).change_time_zone(self)
+ end
begin # the following methods depend on the tzinfo gem
require_library_or_gem "tzinfo" unless Object.const_defined?(:TZInfo)