[前][次][番号順一覧][スレッド一覧]

ruby-changes:11450

From: akr <ko1@a...>
Date: Fri, 27 Mar 2009 01:35:30 +0900 (JST)
Subject: [ruby-changes:11450] Ruby:r23075 (trunk): * time.c (time_cmp): negate the result of reverse comparison.

akr	2009-03-27 01:35:18 +0900 (Fri, 27 Mar 2009)

  New Revision: 23075

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23075

  Log:
    * time.c (time_cmp): negate the result of reverse comparison.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_time.rb
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 23074)
+++ time.c	(revision 23075)
@@ -1113,7 +1113,7 @@
 	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);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23074)
+++ ChangeLog	(revision 23075)
@@ -1,3 +1,7 @@
+Fri Mar 27 01:33:37 2009  Tanaka Akira  <akr@f...>
+
+	* time.c (time_cmp): negate the result of reverse comparison.
+
 Fri Mar 27 01:19:50 2009  Tanaka Akira  <akr@f...>
 
 	* bignum.c (rb_cmpint): FIX2INT may fail on LP64 platforms.
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 23074)
+++ test/ruby/test_time.rb	(revision 23075)
@@ -1,6 +1,7 @@
 require 'test/unit'
 require 'rational'
 require 'timeout'
+require 'delegate'
 
 class TestTime < Test::Unit::TestCase
   def setup
@@ -470,4 +471,13 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]