Skip to content
This repository
Browse code

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
Santiago Pastorino authored April 02, 2010
18  activesupport/lib/active_support/values/time_zone.rb
@@ -177,7 +177,7 @@ class TimeZone
177 177
     # offset is the number of seconds that this time zone is offset from UTC
178 178
     # (GMT). Seconds were chosen as the offset unit because that is the unit that
179 179
     # Ruby uses to represent time zone offsets (see Time#utc_offset).
180  
-    def initialize(name, utc_offset, tzinfo = nil)
  180
+    def initialize(name, utc_offset = nil, tzinfo = nil)
181 181
       @name = name
182 182
       @utc_offset = utc_offset
183 183
       @tzinfo = tzinfo
@@ -185,8 +185,12 @@ def initialize(name, utc_offset, tzinfo = nil)
185 185
     end
186 186
 
187 187
     def utc_offset
188  
-      @current_period ||= tzinfo.current_period
189  
-      @current_period.utc_offset
  188
+      if @utc_offset
  189
+        @utc_offset
  190
+      else
  191
+        @current_period ||= tzinfo.current_period
  192
+        @current_period.utc_offset
  193
+      end
190 194
     end
191 195
 
192 196
     # Returns the offset of this time zone as a formatted string, of the
@@ -288,10 +292,14 @@ def period_for_local(time, dst=true)
288 292
       tzinfo.period_for_local(time, dst)
289 293
     end
290 294
 
291  
-    # TODO: Preload instead of lazy load for thread safety
292 295
     def tzinfo
  296
+      @tzinfo ||= find_tzinfo
  297
+    end
  298
+
  299
+    # TODO: Preload instead of lazy load for thread safety
  300
+    def find_tzinfo
293 301
       require 'tzinfo' unless defined?(TZInfo)
294  
-      @tzinfo ||= TZInfo::Timezone.get(MAPPING[name])
  302
+      ::TZInfo::Timezone.get(MAPPING[name])
295 303
     end
296 304
 
297 305
     unless const_defined?(:ZONES)
5  activesupport/test/time_zone_test.rb
@@ -39,9 +39,8 @@ def test_from_duration_to_map
39 39
       assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[zone.name]
40 40
     end
41 41
 
42  
-    define_method("test_utc_offset_for_#{name}") do
43  
-      period = zone.tzinfo.current_period
44  
-      assert_equal period.utc_offset, zone.utc_offset
  42
+    define_method("test_zones_map_for_#{name}") do
  43
+      assert_equal ActiveSupport::TimeZone::ZONES_MAP[zone.name], zone
45 44
     end
46 45
   end
47 46
 

0 notes on commit de7925d

Please sign in to comment.
Something went wrong with that request. Please try again.