public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Time.zone.parse: compatibility with far future date with time zone offset 
in string. Eliminate creation of additional TimeWithZone instance to 
determine utc offset.
gbuesing (author)
Thu May 08 18:56:38 -0700 2008
commit  fb9bf16e96e2c24d4996327500d8109b5d535e2c
tree    87d0b30af0901868c5604ee2a50b3a8de5807a14
parent  328fada610aa9128386bc4b372d3e0b68aede945
...
214
215
216
217
218
 
 
 
 
219
220
221
222
223
...
214
215
216
 
 
217
218
219
220
221
 
222
223
224
0
@@ -214,10 +214,11 @@
0
   # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
0
   def parse(str, now=now)
0
     time = Time.parse(str, now) rescue DateTime.parse(str)
0
- unless time.is_a?(DateTime) || Date._parse(str)[:offset].nil?
0
- time += time.in_time_zone(self).utc_offset - time.utc_offset
0
+ if Date._parse(str)[:offset].nil?
0
+ ActiveSupport::TimeWithZone.new(nil, self, time)
0
+ else
0
+ time.in_time_zone(self)
0
     end
0
- ActiveSupport::TimeWithZone.new(nil, self, time)
0
   end
0
 
0
   # Returns an ActiveSupport::TimeWithZone instance representing the current time
...
189
190
191
 
 
 
 
 
 
 
 
 
192
193
194
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
0
@@ -189,6 +189,15 @@
0
       assert_equal zone, twz.time_zone
0
     end
0
   end
0
+
0
+ def test_parse_far_future_date_with_time_zone_offset_in_string
0
+ silence_warnings do # silence warnings raised by tzinfo gem
0
+ zone = TimeZone['Eastern Time (US & Canada)']
0
+ twz = zone.parse('2050-12-31 19:00:00 -10:00') # i.e., 2050-01-01 05:00:00 UTC
0
+ assert_equal [0,0,0,1,1,2051], twz.to_a[0,6]
0
+ assert_equal zone, twz.time_zone
0
+ end
0
+ end
0
 
0
   uses_mocha 'TestParseWithIncompleteDate' do
0
     def test_parse_with_incomplete_date

Comments

    No one has commented yet.