diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-03-28 01:57:41 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-03-28 01:57:41 +0000 |
commit | e4645e00b7a427f32e470b4ad3fe494b698f725d (patch) | |
tree | 0722ca35306af6400f79f6b28a022e3a5aae90ee /activesupport | |
parent | 480a7581d4ec87eb745b004d6e4daae98b52cfa5 (diff) | |
download | rails-e4645e00b7a427f32e470b4ad3fe494b698f725d.tar.gz rails-e4645e00b7a427f32e470b4ad3fe494b698f725d.tar.bz2 rails-e4645e00b7a427f32e470b4ad3fe494b698f725d.zip |
TimeWithZone#usec returns 0 instead of error when DateTime is wrapped
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9105 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
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') |