diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-04-28 20:18:26 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-04-28 20:18:26 -0700 |
commit | 1a4e27ff96b3b7add1a4a43ca757ea8ee6c05c00 (patch) | |
tree | 03e64efa0e3a307c0f8f58eadc31fc01e26b1cd7 /activesupport/lib/active_support/core_ext/time/zones.rb | |
parent | ad2c5ea2786817592014fae09934398173c1a7f9 (diff) | |
parent | 432a65fab2a6c7eb6ff77062e73f7627470f7da7 (diff) | |
download | rails-1a4e27ff96b3b7add1a4a43ca757ea8ee6c05c00.tar.gz rails-1a4e27ff96b3b7add1a4a43ca757ea8ee6c05c00.tar.bz2 rails-1a4e27ff96b3b7add1a4a43ca757ea8ee6c05c00.zip |
Merge pull request #5996 from gazay/remove_excess_selfs
Active Support housekeeping and polish
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/zones.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/zones.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb index b4ed74a7b0..e48866abe3 100644 --- a/activesupport/lib/active_support/core_ext/time/zones.rb +++ b/activesupport/lib/active_support/core_ext/time/zones.rb @@ -51,13 +51,21 @@ class Time # Returns a TimeZone instance or nil, or raises an ArgumentError for invalid timezones. def find_zone!(time_zone) - return time_zone if time_zone.nil? || time_zone.is_a?(ActiveSupport::TimeZone) - # lookup timezone based on identifier (unless we've been passed a TZInfo::Timezone) - unless time_zone.respond_to?(:period_for_local) - time_zone = ActiveSupport::TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) + if !time_zone || time_zone.is_a?(ActiveSupport::TimeZone) + time_zone + else + # lookup timezone based on identifier (unless we've been passed a TZInfo::Timezone) + unless time_zone.respond_to?(:period_for_local) + time_zone = ActiveSupport::TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) + end + + # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone + if time_zone.is_a?(ActiveSupport::TimeZone) + time_zone + else + ActiveSupport::TimeZone.create(time_zone.name, nil, time_zone) + end end - # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone - time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone.create(time_zone.name, nil, time_zone) rescue TZInfo::InvalidTimezoneIdentifier raise ArgumentError, "Invalid Timezone: #{time_zone}" end @@ -80,8 +88,10 @@ class Time # # Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00 def in_time_zone(zone = ::Time.zone) - return self unless zone - - ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.find_zone!(zone)) + if zone + ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.find_zone!(zone)) + else + self + end end end |