Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

utc_offset is no longer required on TimeZone and if it's not supplied…

… we delegate to TZInfo
  • Loading branch information...
commit de7925de8a80b5387be27a41abac185b351a746a 1 parent aa48c79
@spastorino spastorino authored
View
18 activesupport/lib/active_support/values/time_zone.rb
@@ -177,7 +177,7 @@ class TimeZone
# 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, tzinfo = nil)
+ def initialize(name, utc_offset = nil, tzinfo = nil)
@name = name
@utc_offset = utc_offset
@tzinfo = tzinfo
@@ -185,8 +185,12 @@ def initialize(name, utc_offset, tzinfo = nil)
end
def utc_offset
- @current_period ||= tzinfo.current_period
- @current_period.utc_offset
+ if @utc_offset
+ @utc_offset
+ else
+ @current_period ||= tzinfo.current_period
+ @current_period.utc_offset
+ end
end
# Returns the offset of this time zone as a formatted string, of the
@@ -288,10 +292,14 @@ def period_for_local(time, dst=true)
tzinfo.period_for_local(time, dst)
end
- # TODO: Preload instead of lazy load for thread safety
def tzinfo
+ @tzinfo ||= find_tzinfo
+ end
+
+ # TODO: Preload instead of lazy load for thread safety
+ def find_tzinfo
require 'tzinfo' unless defined?(TZInfo)
- @tzinfo ||= TZInfo::Timezone.get(MAPPING[name])
+ ::TZInfo::Timezone.get(MAPPING[name])
end
unless const_defined?(:ZONES)
View
5 activesupport/test/time_zone_test.rb
@@ -39,9 +39,8 @@ def test_from_duration_to_map
assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[zone.name]
end
- define_method("test_utc_offset_for_#{name}") do
- period = zone.tzinfo.current_period
- assert_equal period.utc_offset, zone.utc_offset
+ define_method("test_zones_map_for_#{name}") do
+ assert_equal ActiveSupport::TimeZone::ZONES_MAP[zone.name], zone
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.