Permalink
Browse files

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
  • Loading branch information...
1 parent 480a758 commit e4645e00b7a427f32e470b4ad3fe494b698f725d @gbuesing gbuesing committed Mar 28, 2008
View
@@ -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]
@@ -143,7 +143,7 @@ def -(other)
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 @@ def -(other)
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)
@@ -326,6 +326,13 @@ def test_method_missing_with_non_time_return_value
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')

0 comments on commit e4645e0

Please sign in to comment.