Changeset 8720
- Timestamp:
- 01/25/08 18:23:22 (5 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/time_with_zone.rb (modified) (4 diffs)
- trunk/activesupport/lib/active_support/values/time_zone.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/date_time_ext_test.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/time_ext_test.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8719 r8720 1 1 *SVN* 2 3 * Adding UTC zone to TimeZone; TimeWithZone no longer has to fake UTC zone with nil [Geoff Buesing] 2 4 3 5 * Time.get_zone refactored to private method, given that the encapsulated logic is only useful internally [Geoff Buesing] trunk/activesupport/lib/active_support/time_with_zone.rb
r8711 r8720 6 6 attr_reader :time_zone 7 7 8 def initialize(utc_time, time_zone = nil, local_time = nil)8 def initialize(utc_time, time_zone, local_time = nil) 9 9 @utc = utc_time 10 10 @time = local_time … … 14 14 # Returns a Time instance that represents the time in time_zone 15 15 def time 16 @time ||= utc? ? @utc :time_zone.utc_to_local(@utc)16 @time ||= time_zone.utc_to_local(@utc) 17 17 end 18 18 19 19 # Returns a Time instance that represents the time in UTC 20 20 def utc 21 @utc ||= utc? ? @time :time_zone.local_to_utc(@time)21 @utc ||= time_zone.local_to_utc(@time) 22 22 end 23 23 alias_method :comparable_time, :utc … … 54 54 55 55 def dst? 56 utc? ? false :period.dst?56 period.dst? 57 57 end 58 58 59 # The TimeZone class has no zone for UTC, so this class uses the absence of a time zone to indicate UTC60 59 def utc? 61 !time_zone60 time_zone.name == 'UTC' 62 61 end 63 62 64 63 def utc_offset 65 utc? ? 0 :period.utc_total_offset64 period.utc_total_offset 66 65 end 67 66 … … 72 71 # Time uses #zone to display the time zone abbreviation, so we're duck-typing it 73 72 def zone 74 utc? ? 'UTC' :period.abbreviation.to_s73 period.abbreviation.to_s 75 74 end 76 75 trunk/activesupport/lib/active_support/values/time_zone.rb
r8716 r8720 41 41 "Casablanca" => "Africa/Casablanca", 42 42 "Monrovia" => "Africa/Monrovia", 43 "UTC" => "UTC", 43 44 "Belgrade" => "Europe/Belgrade", 44 45 "Bratislava" => "Europe/Bratislava", … … 260 261 [ -3_600, "Azores", "Cape Verde Is." ], 261 262 [ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca", 262 "Monrovia" ],263 "Monrovia", "UTC" ], 263 264 [ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague", 264 265 "Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels", trunk/activesupport/test/core_ext/date_time_ext_test.rb
r8711 r8720 268 268 269 269 def test_compare_with_time_with_zone 270 assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59) )271 assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0) )272 assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1) ))270 assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] ) 271 assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) 272 assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) 273 273 end 274 274 trunk/activesupport/test/core_ext/time_ext_test.rb
r8715 r8720 451 451 452 452 def test_compare_with_time_with_zone 453 assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59) )454 assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0) )455 assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1) ))453 assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] ) 454 assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) 455 assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) 456 456 end 457 457 trunk/activesupport/test/core_ext/time_with_zone_test.rb
r8718 r8720 47 47 def test_utc? 48 48 assert_equal false, @twz.utc? 49 assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000) ).utc?49 assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone['UTC']).utc? 50 50 end 51 51 … … 102 102 103 103 def test_compare_with_time_with_zone 104 assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59) )105 assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0) )106 assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1) ))104 assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] ) 105 assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) 106 assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) 107 107 end 108 108 … … 160 160 def test_in_time_zone 161 161 silence_warnings do # silence warnings raised by tzinfo gem 162 Time.use_zone 'Eastern Time (US & Canada)' do 162 Time.use_zone 'Eastern Time (US & Canada)' do # Time.zone will not affect #in_time_zone(zone) 163 163 assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_time_zone('Alaska').inspect 164 164 assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_time_zone('Alaska').inspect 165 165 assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_time_zone('Hawaii').inspect 166 166 assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_time_zone('Hawaii').inspect 167 assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.in_time_zone('UTC').inspect 168 assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.in_time_zone('UTC').inspect 167 169 end 168 170 end … … 186 188 def test_change_time_zone 187 189 silence_warnings do # silence warnings raised by tzinfo gem 188 Time.use_zone 'Eastern Time (US & Canada)' do 190 Time.use_zone 'Eastern Time (US & Canada)' do # Time.zone will not affect #change_time_zone(zone) 189 191 assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone('Alaska').inspect 190 192 assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @dt.change_time_zone('Alaska').inspect 191 193 assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @t.change_time_zone('Hawaii').inspect 192 194 assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone('Hawaii').inspect 195 assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.change_time_zone('UTC').inspect 196 assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.change_time_zone('UTC').inspect 193 197 end 194 198 end