diff --git a/spec/mysql2/result_spec.rb b/spec/mysql2/result_spec.rb index 35da16b91..5a5fde249 100644 --- a/spec/mysql2/result_spec.rb +++ b/spec/mysql2/result_spec.rb @@ -292,6 +292,30 @@ expect(@test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00') end + it "should return Time values with microseconds" do + now = Time.now + if RUBY_VERSION =~ /1.8/ || Gem::Version.new(@client.server_info.fetch(:version)) < Gem::Version.new('5.6') + result = @client.query("SELECT CAST('#{now.strftime('%F %T %z')}' AS DATETIME) AS a") + expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z')) + else + result = @client.query("SELECT CAST('#{now.strftime('%F %T.%6N %z')}' AS DATETIME(6)) AS a") + # microseconds is 6 digits after the decimal, but only test on 5 significant figures + expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z')) + end + end + + it "should return DateTime values with microseconds" do + now = DateTime.now + if RUBY_VERSION =~ /1.8/ || Gem::Version.new(@client.server_info.fetch(:version)) < Gem::Version.new('5.6') + result = @client.query("SELECT CAST('#{now.strftime('%F %T %z')}' AS DATETIME) AS a") + expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z')) + else + result = @client.query("SELECT CAST('#{now.strftime('%F %T.%6N %z')}' AS DATETIME(6)) AS a") + # microseconds is 6 digits after the decimal, but only test on 5 significant figures + expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z')) + end + end + if 1.size == 4 # 32bit klass = if RUBY_VERSION =~ /1.8/ DateTime diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index c0a16af47..e0fccad53 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -150,7 +150,8 @@ def stmt_count if RUBY_VERSION =~ /1.8/ expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z')) else - expect(result.first['a'].strftime('%F %T.%6N %z')).to eql(now.strftime('%F %T.%6N %z')) + # microseconds is six digits after the decimal, but only test on 5 significant figures + expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z')) end end @@ -161,7 +162,8 @@ def stmt_count if RUBY_VERSION =~ /1.8/ expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z')) else - expect(result.first['a'].strftime('%F %T.%6N %z')).to eql(now.strftime('%F %T.%6N %z')) + # microseconds is six digits after the decimal, but only test on 5 significant figures + expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z')) end end