aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb11
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb9
2 files changed, 16 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 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
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 91f0394472..9b9602432c 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -145,15 +145,20 @@ class TimeZone
}
include Comparable
- attr_reader :name, :utc_offset
+ attr_reader :name
# Create a new TimeZone object with the given name and offset. The
# offset is the number of seconds that this time zone is offset from UTC
# (GMT). Seconds were chosen as the offset unit because that is the unit that
# Ruby uses to represent time zone offsets (see Time#utc_offset).
- def initialize(name, utc_offset)
+ def initialize(name, utc_offset, tzinfo = nil)
@name = name
@utc_offset = utc_offset
+ @tzinfo = tzinfo
+ end
+
+ def utc_offset
+ @utc_offset ||= tzinfo.current_period.utc_offset
end
# Returns the offset of this time zone as a formatted string, of the