[ruby-oci8-commit] [510] trunk/ruby-oci8: fix to pass tests on ruby 1.9.1 and earlier.

nobody at rubyforge.org nobody at rubyforge.org
Sat Apr 21 12:03:15 UTC 2012


Revision: 510
Author:   kubo
Date:     2012-04-21 12:03:15 +0000 (Sat, 21 Apr 2012)
Log Message:
-----------
fix to pass tests on ruby 1.9.1 and earlier.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/test/test_datetime.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2012-04-21 10:57:49 UTC (rev 509)
+++ trunk/ruby-oci8/ChangeLog	2012-04-21 12:03:15 UTC (rev 510)
@@ -1,4 +1,7 @@
 2012-04-21  KUBO Takehiro  <kubo at jiubao.org>
+	* test/test_datetime.rb: fix to pass tests on ruby 1.9.1 and earlier.
+
+2012-04-21  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/oci8.c: fix to raise a RuntimeError when a connection
 	    retrieved from a connection pool is set as non-blocking on 
 	    ruby 1.8.

Modified: trunk/ruby-oci8/test/test_datetime.rb
===================================================================
--- trunk/ruby-oci8/test/test_datetime.rb	2012-04-21 10:57:49 UTC (rev 509)
+++ trunk/ruby-oci8/test/test_datetime.rb	2012-04-21 12:03:15 UTC (rev 510)
@@ -13,15 +13,22 @@
     end
   end
 
+  @@time_new_accepts_timezone = begin
+                                  Time.new(2001, 1, 1, 0, 0, 0, '+00:00')
+                                  true
+                                rescue
+                                  false
+                                end
+
   def string_to_time(str)
-    /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d+:\d+)?/ =~ str
+    /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?(([+-])(\d+):(\d+))?/ =~ str
     args = []
     args << $1.to_i # year
     args << $2.to_i # month
     args << $3.to_i # day
     args << $4.to_i if $4 # hour
     args << $5.to_i if $5 # minute
-    if $8
+    if $8 and @@time_new_accepts_timezone
       args << $6.to_i + $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i
       args << $8
       Time.new(*args)
@@ -32,8 +39,20 @@
       if $7
         args << $7.to_i.to_r * 1000000 / ('1' + '0' * ($7.length)).to_i
       end
-      # no time zone
-      Time.local(*args)
+      if $8
+        # with time zone
+        offset = ($9 + '1').to_i * ($10.to_i * 60 + $11.to_i)
+        if offset == 0
+          Time.utc(*args)
+        else
+          tm = Time.local(*args)
+          raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60
+          tm
+        end
+      else
+        # without time zone
+        Time.local(*args)
+      end
     end
     #Time.local(*str.split(/[- :\.]/).collect do |n| n.to_i; end)
   end



More information about the ruby-oci8-commit mailing list