Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/ruby/ext/trilogy-ruby/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static VALUE trilogy_make_time(int year, int month, int day, int hour, int min,
rb_cTime, id_local, 7,
INT2NUM(year), INT2NUM(month), INT2NUM(day),
INT2NUM(hour), INT2NUM(min), INT2NUM(sec),
INT2NUM(usec / 1000)
INT2NUM(usec)
);
}

Expand Down
27 changes: 17 additions & 10 deletions contrib/ruby/test/cast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ def test_time_cast_with_precision
# --- Tests ported from Go's go-sql-driver/mysql TestParseDateTime ---

def test_datetime_fractional_1_digit
# Go test: "parse datetime nanosec 1-digit" => "2020-05-25 23:22:01.1"
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.1')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]
Expand All @@ -465,7 +464,6 @@ def test_datetime_fractional_1_digit
end

def test_datetime_fractional_2_digits
# Go test: "parse datetime nanosec 2-digits" => "2020-05-25 23:22:01.15"
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.15')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]
Expand All @@ -475,7 +473,6 @@ def test_datetime_fractional_2_digits
end

def test_datetime_fractional_3_digits
# Go test: "parse datetime nanosec 3-digits" => "2020-05-25 23:22:01.159"
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.159')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]
Expand All @@ -485,7 +482,6 @@ def test_datetime_fractional_3_digits
end

def test_datetime_fractional_4_digits
# Go test: "parse datetime nanosec 4-digits" => "2020-05-25 23:22:01.1594"
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.1594')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]
Expand All @@ -495,7 +491,6 @@ def test_datetime_fractional_4_digits
end

def test_datetime_fractional_5_digits
# Go test: "parse datetime nanosec 5-digits" => "2020-05-25 23:22:01.15949"
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.15949')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]
Expand All @@ -505,7 +500,6 @@ def test_datetime_fractional_5_digits
end

def test_datetime_fractional_6_digits
# Go test: "parse datetime nanosec 6-digits" => "2020-05-25 23:22:01.159491"
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.159491')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]
Expand All @@ -520,8 +514,24 @@ def test_datetime_fractional_6_digits
assert_equal 159491, time.usec
end

def test_datetime_fractional_6_digits_localtime
skip unless Time.method_defined?(:iso8601)

tz_before = ENV['TZ']
ENV['TZ'] = 'UTC 0'

@client.query_flags |= Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
@client.query("INSERT INTO trilogy_test (date_time_with_precision_test) VALUES ('2020-05-25 23:22:01.159491')")

time = @client.query("SELECT date_time_with_precision_test FROM trilogy_test").to_a[0][0]

assert_kind_of Time, time
assert_equal "2020-05-25T23:22:01.159491+00:00", time.iso8601(6)
ensure
ENV['TZ'] = tz_before
end

def test_datetime_zero_date_returns_nil
# Go test: "parse null datetime" => "0000-00-00 00:00:00"
@client.query("SET SESSION sql_mode = 'ALLOW_INVALID_DATES'")
@client.query("INSERT INTO trilogy_test (date_time_test) VALUES ('0000-00-00 00:00:00')")

Expand All @@ -530,7 +540,6 @@ def test_datetime_zero_date_returns_nil
end

def test_date_zero_returns_nil
# Go test: "parse null date" => "0000-00-00"
@client.query("SET SESSION sql_mode = 'ALLOW_INVALID_DATES'")
@client.query("INSERT INTO trilogy_test (date_test) VALUES ('0000-00-00')")

Expand All @@ -539,7 +548,6 @@ def test_date_zero_returns_nil
end

def test_datetime_specific_date_parse
# Go test: "parse date" => "2020-05-13"
@client.query("INSERT INTO trilogy_test (date_test) VALUES ('2020-05-13')")

date = @client.query("SELECT date_test FROM trilogy_test").to_a[0][0]
Expand All @@ -551,7 +559,6 @@ def test_datetime_specific_date_parse
end

def test_datetime_specific_datetime_parse
# Go test: "parse datetime" => "2020-05-13 21:30:45"
@client.query("INSERT INTO trilogy_test (date_time_test) VALUES ('2020-05-13 21:30:45')")

time = @client.query("SELECT date_time_test FROM trilogy_test").to_a[0][0]
Expand Down
Loading