aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time/zones.rb
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-28 04:06:47 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-28 04:06:47 +0000
commit59183eec6f8d3e5d1ac5046dbd4f5cefc7041256 (patch)
tree223e06207adb97a74ebd84e43aee4c9b7c50a2af /activesupport/lib/active_support/core_ext/time/zones.rb
parent129d94477b1bb4478d1d8ceaed2a0f9a615e2d23 (diff)
downloadrails-59183eec6f8d3e5d1ac5046dbd4f5cefc7041256.tar.gz
rails-59183eec6f8d3e5d1ac5046dbd4f5cefc7041256.tar.bz2
rails-59183eec6f8d3e5d1ac5046dbd4f5cefc7041256.zip
Time.zone= accepts TZInfo::Timezone instances and Olson identifiers; wraps result in TimeZone instance
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9107 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/zones.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb
index e7610d144f..3096427904 100644
--- a/activesupport/lib/active_support/core_ext/time/zones.rb
+++ b/activesupport/lib/active_support/core_ext/time/zones.rb
@@ -38,8 +38,15 @@ module ActiveSupport #:nodoc:
private
def get_zone(time_zone)
- return time_zone if time_zone.nil? || time_zone.respond_to?(:period_for_local)
- TimeZone[time_zone]
+ return time_zone if time_zone.nil? || time_zone.is_a?(TimeZone)
+ # lookup timezone based on identifier (unless we've been passed a TZInfo::Timezone)
+ unless time_zone.respond_to?(:period_for_local)
+ time_zone = TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) rescue nil
+ end
+ # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone
+ if time_zone
+ time_zone.is_a?(TimeZone) ? time_zone : TimeZone.create(time_zone.name, nil, time_zone)
+ end
end
end