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

ruby-changes:15190

From: akr <ko1@a...>
Date: Sun, 28 Mar 2010 02:16:51 +0900 (JST)
Subject: [ruby-changes:15190] Ruby:r27069 (trunk): * time.c: fix previos commit.

akr	2010-03-28 02:14:13 +0900 (Sun, 28 Mar 2010)

  New Revision: 27069

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

  Log:
    * time.c: fix previos commit.

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

Index: time.c
===================================================================
--- time.c	(revision 27068)
+++ time.c	(revision 27069)
@@ -122,11 +122,12 @@
                 int64_t i = 0;
                 while (len)
                     i = (i << sizeof(BDIGIT)*CHAR_BIT) | ds[--len];
-                TIMEW_SETVAL(w, INT64toFIXTV(i));
+                if (FIXTVABLE(i))
+                    TIMEW_SETVAL(w, INT64toFIXTV(i));
             }
         }
         else {
-            if (ds[len-1] <= ((BDIGIT)1 << (sizeof(BDIGIT)*CHAR_BIT-2))) {
+            if (ds[len-1] < ((BDIGIT)1 << (sizeof(BDIGIT)*CHAR_BIT-2))) {
                 int64_t i = 0;
                 while (len)
                     i = (i << sizeof(BDIGIT)*CHAR_BIT) | ds[--len];
@@ -616,7 +617,7 @@
     int year_mod400;
     int yday = vtm->mday;
     long days_in400;
-    VALUE ret;
+    VALUE vdays, ret;
     timew_t wret;
 
     year1900 = sub(vtm->year, INT2FIX(1900));
@@ -643,9 +644,10 @@
                + DIV(year_mod400 - 69, 4)
                - DIV(year_mod400 - 1, 100)
                + (year_mod400 + 299) / 400;
-    ret = add(ret, mul(LONG2NUM(days_in400), INT2FIX(86400)));
-    ret = add(ret, mul(q400, INT2FIX(97*86400)));
-    ret = add(ret, mul(year1900, INT2FIX(365*86400)));
+    vdays = LONG2NUM(days_in400);
+    vdays = add(vdays, mul(q400, INT2FIX(97)));
+    vdays = add(vdays, mul(year1900, INT2FIX(365)));
+    ret = add(ret, mul(vdays, INT2FIX(86400)));
     wret = wadd(rb_time_magnify(ret), xv2w(vtm->subsecx));
 
     return wret;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27068)
+++ ChangeLog	(revision 27069)
@@ -1,3 +1,7 @@
+2010-03-27  Tanaka Akira  <akr@f...>
+
+	* time.c: fix previos commit.
+
 Sat Mar 27 23:17:52 2010  Tanaka Akira  <akr@f...>
 
 	* time.c: use 64bit arithmetic even on platforms with 32bit VALUE.
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 27068)
+++ test/ruby/test_time.rb	(revision 27069)
@@ -162,6 +162,16 @@
       assert_equal(999999998, Time.at(-14e-10).nsec)
       assert_equal(999999998, Time.at(-16e-10).nsec)
     end
+
+    t = Time.at(-4611686019).utc
+    assert_equal(1823, t.year)
+
+    t = Time.at(4611686018, 999999).utc
+    assert_equal(2116, t.year)
+    assert_equal("0.999999".to_r, t.subsec)
+
+    t = Time.at(2**40 + "1/3".to_r, 9999999999999).utc
+    assert_equal(36812, t.year)
   end
 
   def test_at2
@@ -287,6 +297,9 @@
 
     t = Time.local(2000)
     assert_equal(t.gmt_offset, T2000 - t)
+
+    assert_equal(-4427700000, Time.utc(-4427700000,12,1).year)
+    assert_equal(-2**30+10, Time.utc(-2**30+10,1,1).year)
   end
 
   def test_time_interval
@@ -407,6 +420,11 @@
     assert_equal(Rational(1,3), (t0 + SimpleDelegator.new(Rational(4,3))).subsec)
   end
 
+  def test_minus
+    t = Time.at(-4611686018).utc - 100
+    assert_equal(1823, t.year)
+  end
+
   def test_readers
     assert_equal(0, T2000.sec)
     assert_equal(0, T2000.min)

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

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