1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* time.c (time_to_r): convert to rational if internal representation

is not rational.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-01-13 23:51:16 +00:00
parent 49ab7b4238
commit 4bf4ddb693
3 changed files with 16 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Thu Jan 14 08:49:59 2010 Tanaka Akira <akr@fsij.org>
* time.c (time_to_r): convert to rational if internal representation
is not rational.
Thu Jan 14 04:01:50 2010 Tanaka Akira <akr@fsij.org>
* time.c (time_mdump): use nano_num and nano_den instead of subnano to

View file

@ -540,4 +540,9 @@ class TestTime < Test::Unit::TestCase
assert_equal(-1, d1 <=> d2)
assert_equal(1, d2 <=> d1)
end
def test_to_r
assert_kind_of(Rational, Time.new(2000,1,1,0,0,Rational(4,3)).to_r)
assert_kind_of(Rational, Time.utc(1970).to_r)
end
end

7
time.c
View file

@ -2425,9 +2425,14 @@ static VALUE
time_to_r(VALUE time)
{
struct time_object *tobj;
VALUE v;
GetTimeval(time, tobj);
return rb_time_unmagnify(tobj->timexv);
v = rb_time_unmagnify(tobj->timexv);
if (TYPE(v) != T_RATIONAL) {
v = rb_convert_type(v, T_RATIONAL, "Rational", "to_r");
}
return v;
}
/*