Skip to content

Instantly share code, notes, and snippets.

@ebryn
Created October 21, 2010 19:12
Show Gist options
  • Save ebryn/639107 to your computer and use it in GitHub Desktop.
Save ebryn/639107 to your computer and use it in GitHub Desktop.
diff --git a/ext/tiny_tds/result.c b/ext/tiny_tds/result.c
index 1aef319..8ac897c 100644
--- a/ext/tiny_tds/result.c
+++ b/ext/tiny_tds/result.c
@@ -164,12 +164,16 @@ static VALUE rb_tinytds_result_fetch_row(VALUE self, ID timezone, int symbolize_
if (year < 1902 || year+month+day > 2058) {
VALUE datetime_sec = INT2NUM(sec);
if (msec != 0) {
- #ifdef HAVE_RUBY_ENCODING_H
- VALUE rational_msec = rb_Rational2(INT2NUM(msec*1000), opt_onemil);
- #else
- VALUE rational_msec = rb_funcall(rb_cObject, intern_Rational, 2, INT2NUM(msec*1000), opt_onemil);
- #endif
- datetime_sec = rb_funcall(datetime_sec, intern_plus, 1, rational_msec);
+ if ( (strcmp(ruby_version, "1.8.6") == 0 && sec < 59) ||
+ (strcmp(ruby_version, "1.8.6") != 0 ) )
+ {
+ #ifdef HAVE_RUBY_ENCODING_H
+ VALUE rational_msec = rb_Rational2(INT2NUM(msec*1000), opt_onemil);
+ #else
+ VALUE rational_msec = rb_funcall(rb_cObject, intern_Rational, 2, INT2NUM(msec*1000), opt_onemil);
+ #endif
+ datetime_sec = rb_funcall(datetime_sec, intern_plus, 1, rational_msec);
+ }
}
val = rb_funcall(cDateTime, intern_civil, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), datetime_sec, offset);
val = rb_funcall(val, intern_new_offset, 1, offset);
diff --git a/ext/tiny_tds/tiny_tds_ext.h b/ext/tiny_tds/tiny_tds_ext.h
index 396d84c..1a92331 100644
--- a/ext/tiny_tds/tiny_tds_ext.h
+++ b/ext/tiny_tds/tiny_tds_ext.h
@@ -3,6 +3,7 @@
#define MSDBLIB
#include <ruby.h>
+#include <ruby/version.h>
#include <sqlfront.h>
#include <sybdb.h>
#include <syberror.h>
diff --git a/test/schema_test.rb b/test/schema_test.rb
index a904c2e..433b2cd 100644
--- a/test/schema_test.rb
+++ b/test/schema_test.rb
@@ -56,7 +56,7 @@ class SchemaTest < TinyTds::TestCase
assert_equal 23, v.hour
assert_equal 59, v.min
assert_equal 59, v.sec
- assert_equal 997000, v.usec
+ assert_equal 997000, v.usec unless ruby186?
assert_equal local_offset, find_value(61, :datetime, :timezone => :local).offset
assert_equal 0, find_value(61, :datetime, :timezone => :utc).offset
# 2010-01-01T12:34:56.123
diff --git a/test/test_helper.rb b/test/test_helper.rb
index d60cdab..4550232 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -94,6 +94,10 @@ module TinyTds
RUBY_VERSION < '1.9'
end
+ def ruby186?
+ RUBY_VERSION == '1.8.6'
+ end
+
def ruby19?
RUBY_VERSION >= '1.9'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment