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

ruby-changes:22390

From: naruse <ko1@a...>
Date: Mon, 6 Feb 2012 20:32:00 +0900 (JST)
Subject: [ruby-changes:22390] naruse:r34439 (ruby_1_9_3): merge revision(s) 34072,34075,34082:

naruse	2012-02-06 20:31:46 +0900 (Mon, 06 Feb 2012)

  New Revision: 34439

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

  Log:
    merge revision(s) 34072,34075,34082:
    
    * ext/date/date_core.c:  [ruby-dev:45008].
    
    * ext/date/date_core.c (wholenum): fix the type of the return value.
    
    * ext/date/date_core.c: uses to_integer instead.
    
    * test/date/test_switch_hitter.rb: added a test.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ext/date/date_core.c
    branches/ruby_1_9_3/test/date/test_switch_hitter.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 34438)
+++ ruby_1_9_3/ChangeLog	(revision 34439)
@@ -1,3 +1,16 @@
+Mon Feb  6 20:31:35 2012  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c: uses to_integer instead.
+	* test/date/test_switch_hitter.rb: added a test.
+
+Mon Feb  6 20:31:35 2012  NARUSE, Yui  <naruse@r...>
+
+	* ext/date/date_core.c (wholenum): fix the type of the return value.
+
+Mon Feb  6 20:31:35 2012  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c:  [ruby-dev:45008].
+
 Mon Feb  6 16:38:56 2012  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (unixtime_to_filetime): should check the return value
Index: ruby_1_9_3/ext/date/date_core.c
===================================================================
--- ruby_1_9_3/ext/date/date_core.c	(revision 34438)
+++ ruby_1_9_3/ext/date/date_core.c	(revision 34439)
@@ -39,6 +39,7 @@
 #define f_truncate(x) rb_funcall(x, rb_intern("truncate"), 0)
 #define f_round(x) rb_funcall(x, rb_intern("round"), 0)
 
+#define f_to_i(x) rb_funcall(x, rb_intern("to_i"), 0)
 #define f_to_r(x) rb_funcall(x, rb_intern("to_r"), 0)
 #define f_to_s(x) rb_funcall(x, rb_intern("to_s"), 0)
 #define f_inspect(x) rb_funcall(x, rb_intern("inspect"), 0)
@@ -1324,8 +1325,10 @@
 static void
 decode_jd(VALUE jd, VALUE *nth, int *rjd)
 {
+    assert(FIXNUM_P(jd) || RB_TYPE_P(jd, T_BIGNUM));
     *nth = f_idiv(jd, INT2FIX(CM_PERIOD));
     if (f_zero_p(*nth)) {
+	assert(FIXNUM_P(jd));
 	*rjd = FIX2INT(jd);
 	return;
     }
@@ -3095,14 +3098,23 @@
 }
 
 inline static VALUE
+to_integer(VALUE x)
+{
+    if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
+	return x;
+    return f_to_i(x);
+}
+
+inline static VALUE
 d_trunc(VALUE d, VALUE *fr)
 {
     VALUE rd;
 
     if (wholenum_p(d)) {
-	rd = d;
+	rd = to_integer(d);
 	*fr = INT2FIX(0);
-    } else {
+    }
+    else {
 	rd = f_idiv(d, INT2FIX(1));
 	*fr = f_mod(d, INT2FIX(1));
     }
@@ -3118,9 +3130,10 @@
     VALUE rh;
 
     if (wholenum_p(h)) {
-	rh = h;
+	rh = to_integer(h);
 	*fr = INT2FIX(0);
-    } else {
+    }
+    else {
 	rh = f_idiv(h, INT2FIX(1));
 	*fr = f_mod(h, INT2FIX(1));
 	*fr = f_quo(*fr, INT2FIX(24));
@@ -3134,9 +3147,10 @@
     VALUE rmin;
 
     if (wholenum_p(min)) {
-	rmin = min;
+	rmin = to_integer(min);
 	*fr = INT2FIX(0);
-    } else {
+    }
+    else {
 	rmin = f_idiv(min, INT2FIX(1));
 	*fr = f_mod(min, INT2FIX(1));
 	*fr = f_quo(*fr, INT2FIX(1440));
@@ -3150,9 +3164,10 @@
     VALUE rs;
 
     if (wholenum_p(s)) {
-	rs = s;
+	rs = to_integer(s);
 	*fr = INT2FIX(0);
-    } else {
+    }
+    else {
 	rs = f_idiv(s, INT2FIX(1));
 	*fr = f_mod(s, INT2FIX(1));
 	*fr = f_quo(*fr, INT2FIX(86400));
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 34438)
+++ ruby_1_9_3/version.h	(revision 34439)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 36
+#define RUBY_PATCHLEVEL 37
 
 #define RUBY_RELEASE_DATE "2012-02-06"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/date/test_switch_hitter.rb
===================================================================
--- ruby_1_9_3/test/date/test_switch_hitter.rb	(revision 34438)
+++ ruby_1_9_3/test/date/test_switch_hitter.rb	(revision 34439)
@@ -180,6 +180,75 @@
 		 [d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
   end
 
+  def test_fractional
+    d = Date.jd(2451944.0)
+    assert_equal(2451944, d.jd)
+    d = Date.jd(Rational(2451944))
+    assert_equal(2451944, d.jd)
+    d = Date.jd(2451944.5)
+    assert_equal([2451944, 12], [d.jd, d.send('hour')])
+    d = Date.jd(Rational('2451944.5'))
+    assert_equal([2451944, 12], [d.jd, d.send('hour')])
+
+    d = Date.civil(2001, 2, 3.0)
+    assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
+    d = Date.civil(2001, 2, Rational(3))
+    assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
+    d = Date.civil(2001, 2, 3.5)
+    assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')])
+    d = Date.civil(2001, 2, Rational('3.5'))
+    assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')])
+
+    d = Date.ordinal(2001, 2.0)
+    assert_equal([2001, 2], [d.year, d.yday])
+    d = Date.ordinal(2001, Rational(2))
+    assert_equal([2001, 2], [d.year, d.yday])
+
+    d = Date.commercial(2001, 2, 3.0)
+    assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday])
+    d = Date.commercial(2001, 2, Rational(3))
+    assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday])
+
+    d = DateTime.jd(2451944.0)
+    assert_equal(2451944, d.jd)
+    d = DateTime.jd(Rational(2451944))
+    assert_equal(2451944, d.jd)
+    d = DateTime.jd(2451944.5)
+    assert_equal([2451944, 12], [d.jd, d.hour])
+    d = DateTime.jd(Rational('2451944.5'))
+    assert_equal([2451944, 12], [d.jd, d.hour])
+
+    d = DateTime.civil(2001, 2, 3.0)
+    assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
+    d = DateTime.civil(2001, 2, Rational(3))
+    assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
+    d = DateTime.civil(2001, 2, 3.5)
+    assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.hour])
+    d = DateTime.civil(2001, 2, Rational('3.5'))
+    assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.hour])
+    d = DateTime.civil(2001, 2, 3, 4.5)
+    assert_equal([2001, 2, 3, 4, 30], [d.year, d.mon, d.mday, d.hour, d.min])
+    d = DateTime.civil(2001, 2, 3, Rational('4.5'))
+    assert_equal([2001, 2, 3, 4, 30], [d.year, d.mon, d.mday, d.hour, d.min])
+    d = DateTime.civil(2001, 2, 3, 4, 5.5)
+    assert_equal([2001, 2, 3, 4, 5, 30],
+		 [d.year, d.mon, d.mday, d.hour, d.min, d.sec])
+    d = DateTime.civil(2001, 2, 3, 4, Rational('5.5'))
+    assert_equal([2001, 2, 3, 4, 5, 30],
+		 [d.year, d.mon, d.mday, d.hour, d.min, d.sec])
+
+    d = DateTime.ordinal(2001, 2.0)
+    assert_equal([2001, 2], [d.year, d.yday])
+    d = DateTime.ordinal(2001, Rational(2))
+    assert_equal([2001, 2], [d.year, d.yday])
+
+    d = DateTime.commercial(2001, 2, 3.0)
+    assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday])
+    d = DateTime.commercial(2001, 2, Rational(3))
+    assert_equal([2001, 2, 3], [d.cwyear, d.cweek, d.cwday])
+
+  end
+
   def test_canon24oc
     d = DateTime.jd(2451943,24)
     assert_equal([2001, 2, 3, 0, 0, 0, 0],

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

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