aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-13 23:51:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-13 23:51:16 +0000
commit4bf4ddb693b885a5ce9b9ad983c4743627ae29cc (patch)
tree1043eb3bd33ff94f689ab70f8153079c5be80d42
parent49ab7b42383ecd1d8194e17f52c8e3f9273e1459 (diff)
downloadruby-4bf4ddb693b885a5ce9b9ad983c4743627ae29cc.tar.gz
* 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
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_time.rb5
-rw-r--r--time.c7
3 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 33e1c062dd..9b9e186a09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index e6d5d31d80..39a8e297bb 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -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
diff --git a/time.c b/time.c
index 70f0bb65ae..2d5edbe338 100644
--- a/time.c
+++ b/time.c
@@ -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;
}
/*