提交 4f03190f 编写于 作者: G gbuesing

TimeWithZone: date part getter methods (#year #mon #day etc) are defined on...

TimeWithZone: date part getter methods (#year #mon #day etc) are defined on class; no longer relying on method_missing
上级 618d695f
*SVN*
* TimeWithZone: date part getter methods (#year #mon #day etc) are defined on class; no longer relying on method_missing [Geoff Buesing]
* Time.zone.parse return nil for strings with no date information [Geoff Buesing]
* Time.zone.parse respects offset information in string. Resolves #105. [Scott Fleckenstein, Geoff Buesing]
......
......@@ -163,6 +163,14 @@ def advance(options)
utc.advance(options).in_time_zone(time_zone)
end
%w(year mon month day mday hour min sec).each do |method_name|
class_eval <<-EOV
def #{method_name}
time.#{method_name}
end
EOV
end
def usec
time.respond_to?(:usec) ? time.usec : 0
end
......
......@@ -328,10 +328,18 @@ def test_marshal_dump_and_load_with_tzinfo_identifier
assert_equal Time.utc(1999, 12, 31, 19), mtime.time
end
end
def test_method_missing_with_non_time_return_value
silence_warnings do # silence warnings raised by tzinfo gem
@twz.time.expects(:foo).returns('bar')
assert_equal 'bar', @twz.foo
end
end
def test_date_part_value_methods
silence_warnings do # silence warnings raised by tzinfo gem
twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone)
twz.stubs(:method_missing).returns(nil) #ensure these methods are defined directly on class
assert_equal 1999, twz.year
assert_equal 12, twz.month
assert_equal 31, twz.day
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册