Changeset 9107
- Timestamp:
- 03/28/08 04:06:47 (4 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/zones.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/values/time_zone.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (1 diff)
- trunk/activesupport/test/time_zone_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r9106 r9107 1 1 *SVN* 2 3 * Time.zone= accepts TZInfo::Timezone instances and Olson identifiers; wraps result in TimeZone instance [Geoff Buesing] 2 4 3 5 * TimeWithZone time conversions don't need to be wrapped in TimeOrDateTime, because TZInfo does this internally [Geoff Buesing] trunk/activesupport/lib/active_support/core_ext/time/zones.rb
r9093 r9107 39 39 private 40 40 def get_zone(time_zone) 41 return time_zone if time_zone.nil? || time_zone.respond_to?(:period_for_local) 42 TimeZone[time_zone] 41 return time_zone if time_zone.nil? || time_zone.is_a?(TimeZone) 42 # lookup timezone based on identifier (unless we've been passed a TZInfo::Timezone) 43 unless time_zone.respond_to?(:period_for_local) 44 time_zone = TimeZone[time_zone] || TZInfo::Timezone.get(time_zone) rescue nil 45 end 46 # Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone 47 if time_zone 48 time_zone.is_a?(TimeZone) ? time_zone : TimeZone.create(time_zone.name, nil, time_zone) 49 end 43 50 end 44 51 end trunk/activesupport/lib/active_support/values/time_zone.rb
r9071 r9107 146 146 147 147 include Comparable 148 attr_reader :name , :utc_offset148 attr_reader :name 149 149 150 150 # Create a new TimeZone object with the given name and offset. The … … 152 152 # (GMT). Seconds were chosen as the offset unit because that is the unit that 153 153 # Ruby uses to represent time zone offsets (see Time#utc_offset). 154 def initialize(name, utc_offset )154 def initialize(name, utc_offset, tzinfo = nil) 155 155 @name = name 156 156 @utc_offset = utc_offset 157 @tzinfo = tzinfo 158 end 159 160 def utc_offset 161 @utc_offset ||= tzinfo.current_period.utc_offset 157 162 end 158 163 trunk/activesupport/test/core_ext/time_with_zone_test.rb
r9106 r9107 484 484 end 485 485 486 def test_time_zone_setter_with_tzinfo_timezone_object_wraps_in_rails_time_zone 487 silence_warnings do # silence warnings raised by tzinfo gem 488 tzinfo = TZInfo::Timezone.get('America/New_York') 489 Time.zone = tzinfo 490 assert_kind_of TimeZone, Time.zone 491 assert_equal tzinfo, Time.zone.tzinfo 492 assert_equal 'America/New_York', Time.zone.name 493 assert_equal(-18_000, Time.zone.utc_offset) 494 end 495 end 496 497 def test_time_zone_setter_with_tzinfo_timezone_identifier_does_lookup_and_wraps_in_rails_time_zone 498 silence_warnings do # silence warnings raised by tzinfo gem 499 Time.zone = 'America/New_York' 500 assert_kind_of TimeZone, Time.zone 501 assert_equal 'America/New_York', Time.zone.tzinfo.name 502 assert_equal 'America/New_York', Time.zone.name 503 assert_equal(-18_000, Time.zone.utc_offset) 504 end 505 end 506 507 def test_time_zone_setter_with_non_identifying_argument_returns_nil 508 Time.zone = 'foo' 509 assert_equal nil, Time.zone 510 Time.zone = -15.hours 511 assert_equal nil, Time.zone 512 end 513 486 514 protected 487 515 def with_env_tz(new_tz = 'US/Eastern') trunk/activesupport/test/time_zone_test.rb
r9071 r9107 193 193 end 194 194 end 195 196 def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize 197 silence_warnings do # silence warnings raised by tzinfo gem 198 tzinfo = TZInfo::Timezone.get('America/New_York') 199 zone = TimeZone.create(tzinfo.name, nil, tzinfo) 200 assert_equal nil, zone.instance_variable_get('@utc_offset') 201 assert_equal(-18_000, zone.utc_offset) 202 end 203 end 195 204 end 196 205