From 8d888cf451054ca96b5cfbcee057d8d726a30ac5 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 26 Mar 2009 16:35:18 +0000 Subject: * time.c (time_cmp): negate the result of reverse comparison. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ test/ruby/test_time.rb | 10 ++++++++++ time.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a274ad3f8..e8e84cdb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Mar 27 01:33:37 2009 Tanaka Akira + + * time.c (time_cmp): negate the result of reverse comparison. + Fri Mar 27 01:19:50 2009 Tanaka Akira * bignum.c (rb_cmpint): FIX2INT may fail on LP64 platforms. diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index b56fae083..c159ce724 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -1,6 +1,7 @@ require 'test/unit' require 'rational' require 'timeout' +require 'delegate' class TestTime < Test::Unit::TestCase def setup @@ -470,4 +471,13 @@ class TestTime < Test::Unit::TestCase assert_equal("JAN", T2000.strftime("%#h")) assert_equal("FRIDAY", Time.local(2008,1,4).strftime("%#A")) end + + def test_delegate + d1 = SimpleDelegator.new(t1 = Time.utc(2000)) + d2 = SimpleDelegator.new(t2 = Time.utc(2001)) + assert_equal(-1, t1 <=> t2) + assert_equal(1, t2 <=> t1) + assert_equal(-1, d1 <=> d2) + assert_equal(1, d2 <=> d1) + end end diff --git a/time.c b/time.c index 588d4fafb..45ae0ee62 100644 --- a/time.c +++ b/time.c @@ -1113,7 +1113,7 @@ time_cmp(VALUE time1, VALUE time2) cmp = rb_funcall(time2, rb_intern("<=>"), 1, time1); if (NIL_P(cmp)) return Qnil; - n = rb_cmpint(cmp, time1, time2); + n = -rb_cmpint(cmp, time1, time2); if (n == 0) return INT2FIX(0); if (n > 0) return INT2FIX(1); return INT2FIX(-1); -- cgit