Changeset 8731
- Timestamp:
- 01/26/08 00:11:59 (9 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/test/core_ext/date_ext_test.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/date_time_ext_test.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/time_ext_test.rb (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8730 r8731 1 1 *SVN* 2 3 * with_timezone test helper renamed with_env_tz, to distinguish between setting ENV['TZ'] and setting Time.zone in tests [Geoff Buesing] 2 4 3 5 * Time#- coerces TimeWithZone argument to a Time instance so that difference in seconds can be calculated. Closes #10914 [Geoff Buesing, yyyc514] trunk/activesupport/test/core_ext/date_ext_test.rb
r8563 r8731 176 176 177 177 def test_xmlschema 178 with_ timezone'US/Eastern' do178 with_env_tz 'US/Eastern' do 179 179 assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) 180 180 assert_match(/^1980-06-28T00:00:00-04:?00$/, Date.new(1980, 6, 28).xmlschema) … … 188 188 189 189 protected 190 def with_ timezone(new_tz = 'US/Eastern')190 def with_env_tz(new_tz = 'US/Eastern') 191 191 old_tz, ENV['TZ'] = ENV['TZ'], new_tz 192 192 yield trunk/activesupport/test/core_ext/date_time_ext_test.rb
r8720 r8731 213 213 214 214 def test_local_offset 215 with_ timezone'US/Eastern' do215 with_env_tz 'US/Eastern' do 216 216 assert_equal Rational(-5, 24), DateTime.local_offset 217 217 end 218 with_ timezone'US/Central' do218 with_env_tz 'US/Central' do 219 219 assert_equal Rational(-6, 24), DateTime.local_offset 220 220 end … … 274 274 275 275 protected 276 def with_ timezone(new_tz = 'US/Eastern')276 def with_env_tz(new_tz = 'US/Eastern') 277 277 old_tz, ENV['TZ'] = ENV['TZ'], new_tz 278 278 yield trunk/activesupport/test/core_ext/time_ext_test.rb
r8730 r8731 11 11 12 12 def test_seconds_since_midnight_at_daylight_savings_time_start 13 with_ timezone'US/Eastern' do13 with_env_tz 'US/Eastern' do 14 14 # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT 15 15 assert_equal 2*3600-1, Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start' … … 17 17 end 18 18 19 with_ timezone'NZ' do19 with_env_tz 'NZ' do 20 20 # dt: New Zealand: 2006 October 1st 2:00am ST => October 1st 3:00am DT 21 21 assert_equal 2*3600-1, Time.local(2006,10,1,1,59,59).seconds_since_midnight, 'just before DST start' … … 25 25 26 26 def test_seconds_since_midnight_at_daylight_savings_time_end 27 with_ timezone'US/Eastern' do27 with_env_tz 'US/Eastern' do 28 28 # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST 29 29 # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active … … 37 37 end 38 38 39 with_ timezone'NZ' do39 with_env_tz 'NZ' do 40 40 # st: New Zealand: 2006 March 19th 3:00am DT => March 19th 2:00am ST 41 41 # avoid setting a time between 2:00 and 3:00 since that requires specifying whether DST is active … … 63 63 def test_beginning_of_day 64 64 assert_equal Time.local(2005,2,4,0,0,0), Time.local(2005,2,4,10,10,10).beginning_of_day 65 with_ timezone'US/Eastern' do65 with_env_tz 'US/Eastern' do 66 66 assert_equal Time.local(2006,4,2,0,0,0), Time.local(2006,4,2,10,10,10).beginning_of_day, 'start DST' 67 67 assert_equal Time.local(2006,10,29,0,0,0), Time.local(2006,10,29,10,10,10).beginning_of_day, 'ends DST' 68 68 end 69 with_ timezone'NZ' do69 with_env_tz 'NZ' do 70 70 assert_equal Time.local(2006,3,19,0,0,0), Time.local(2006,3,19,10,10,10).beginning_of_day, 'ends DST' 71 71 assert_equal Time.local(2006,10,1,0,0,0), Time.local(2006,10,1,10,10,10).beginning_of_day, 'start DST' … … 146 146 147 147 def test_daylight_savings_time_crossings_backward_start 148 with_ timezone'US/Eastern' do148 with_env_tz 'US/Eastern' do 149 149 # dt: US: 2005 April 3rd 4:18am 150 150 assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-1.day=>st' 151 151 assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st' 152 152 end 153 with_ timezone'NZ' do153 with_env_tz 'NZ' do 154 154 # dt: New Zealand: 2006 October 1st 4:18am 155 155 assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(86400), 'dt-1.day=>st' … … 159 159 160 160 def test_daylight_savings_time_crossings_backward_end 161 with_ timezone'US/Eastern' do161 with_env_tz 'US/Eastern' do 162 162 # st: US: 2005 October 30th 4:03am 163 163 assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-1.day=>dt' 164 164 assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt' 165 165 end 166 with_ timezone'NZ' do166 with_env_tz 'NZ' do 167 167 # st: New Zealand: 2006 March 19th 4:03am 168 168 assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(86400), 'st-1.day=>dt' … … 181 181 182 182 def test_daylight_savings_time_crossings_forward_start 183 with_ timezone'US/Eastern' do183 with_env_tz 'US/Eastern' do 184 184 # st: US: 2005 April 2nd 7:27pm 185 185 assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt' 186 186 assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt' 187 187 end 188 with_ timezone'NZ' do188 with_env_tz 'NZ' do 189 189 # st: New Zealand: 2006 September 30th 7:27pm 190 190 assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(86400), 'st+1.day=>dt' … … 194 194 195 195 def test_daylight_savings_time_crossings_forward_end 196 with_ timezone'US/Eastern' do196 with_env_tz 'US/Eastern' do 197 197 # dt: US: 2005 October 30th 12:45am 198 198 assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(86400), 'dt+1.day=>st' 199 199 assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400), 'st+1.day=>st' 200 200 end 201 with_ timezone'NZ' do201 with_env_tz 'NZ' do 202 202 # dt: New Zealand: 2006 March 19th 1:45am 203 203 assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(86400), 'dt+1.day=>st' … … 276 276 277 277 def test_next_week 278 with_ timezone'US/Eastern' do278 with_env_tz 'US/Eastern' do 279 279 assert_equal Time.local(2005,2,28), Time.local(2005,2,22,15,15,10).next_week 280 280 assert_equal Time.local(2005,3,1), Time.local(2005,2,22,15,15,10).next_week(:tuesday) … … 286 286 287 287 def test_next_week_near_daylight_start 288 with_ timezone'US/Eastern' do288 with_env_tz 'US/Eastern' do 289 289 assert_equal Time.local(2006,4,3), Time.local(2006,4,2,23,1,0).next_week, 'just crossed standard => daylight' 290 290 end 291 with_ timezone'NZ' do291 with_env_tz 'NZ' do 292 292 assert_equal Time.local(2006,10,2), Time.local(2006,10,1,23,1,0).next_week, 'just crossed standard => daylight' 293 293 end … … 295 295 296 296 def test_next_week_near_daylight_end 297 with_ timezone'US/Eastern' do297 with_env_tz 'US/Eastern' do 298 298 assert_equal Time.local(2006,10,30), Time.local(2006,10,29,23,1,0).next_week, 'just crossed daylight => standard' 299 299 end 300 with_ timezone'NZ' do300 with_env_tz 'NZ' do 301 301 assert_equal Time.local(2006,3,20), Time.local(2006,3,19,23,1,0).next_week, 'just crossed daylight => standard' 302 302 end … … 312 312 assert_equal "February 21, 2005 17:44", time.to_s(:long) 313 313 assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal) 314 with_ timezone"UTC" do314 with_env_tz "UTC" do 315 315 assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822) 316 316 end … … 329 329 def test_to_datetime 330 330 assert_equal Time.utc(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, 0, 0) 331 with_ timezone'US/Eastern' do331 with_env_tz 'US/Eastern' do 332 332 assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) 333 333 end 334 with_ timezone'NZ' do334 with_env_tz 'NZ' do 335 335 assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) 336 336 end … … 430 430 431 431 def test_formatted_offset_with_local 432 with_ timezone'US/Eastern' do432 with_env_tz 'US/Eastern' do 433 433 assert_equal '-05:00', Time.local(2000).formatted_offset 434 434 assert_equal '-0500', Time.local(2000).formatted_offset(false) … … 461 461 462 462 protected 463 def with_ timezone(new_tz = 'US/Eastern')463 def with_env_tz(new_tz = 'US/Eastern') 464 464 old_tz, ENV['TZ'] = ENV['TZ'], new_tz 465 465 yield