diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 6 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 7 |
3 files changed, 14 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index ff9cd4d979..e1b4b9a516 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* TimeWithZone#usec returns 0 instead of error when DateTime is wrapped [Geoff Buesing] + * Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] * Ensure that TimeWithZone#to_yaml works when passed a YAML::Emitter. [rick] diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 56c4f40f32..3c37ab2d4c 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -143,7 +143,7 @@ module ActiveSupport end end - %w(asctime day hour min mon sec usec wday yday year to_date).each do |name| + %w(asctime day hour min mon sec wday yday year to_date).each do |name| define_method(name) do time.__send__(name) end @@ -152,6 +152,10 @@ module ActiveSupport alias_method :mday, :day alias_method :month, :mon + def usec + time.respond_to?(:usec) ? time.usec : 0 + end + %w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name| define_method(name) do time.__send__(name) diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 70b3d90bd6..4fe1be3ed6 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -326,6 +326,13 @@ uses_tzinfo 'TimeWithZoneTest' do end end + def test_usec_returns_0_when_datetime_is_wrapped + silence_warnings do # silence warnings raised by tzinfo gem + twz = ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone) + assert_equal 0, twz.usec + end + end + def test_utc_to_local_conversion_saves_period_in_instance_variable silence_warnings do # silence warnings raised by tzinfo gem assert_nil @twz.instance_variable_get('@period') |