From 17aa08736bc18c1cca2866278c34b46175497e85 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Thu, 6 Jul 2023 15:48:52 +0200 Subject: [PATCH] Fix casting of the time type A time of 00:00:00 is perfectly valid, so we should not cast that to a nil. That results in incorrect values. --- contrib/ruby/ext/trilogy-ruby/cast.c | 4 ---- contrib/ruby/test/cast_test.rb | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/contrib/ruby/ext/trilogy-ruby/cast.c b/contrib/ruby/ext/trilogy-ruby/cast.c index 15dbe836..c3e629cc 100644 --- a/contrib/ruby/ext/trilogy-ruby/cast.c +++ b/contrib/ruby/ext/trilogy-ruby/cast.c @@ -233,10 +233,6 @@ rb_trilogy_cast_value(const trilogy_value_t *value, const struct column_info *co return Qnil; } - if (hour == 0 && min == 0 && sec == 0) { - return Qnil; - } - // pad out msec_char with zeroes at the end as it could be at any // level of precision for (size_t i = strlen(msec_char); i < sizeof(msec_char) - 1; i++) { diff --git a/contrib/ruby/test/cast_test.rb b/contrib/ruby/test/cast_test.rb index a0261168..d78ea2f8 100644 --- a/contrib/ruby/test/cast_test.rb +++ b/contrib/ruby/test/cast_test.rb @@ -254,6 +254,23 @@ def test_time_cast_local assert_kind_of Time, results[0][0] end + def test_time_zero + time = Time.utc(2000, 1, 1, 0, 0, 0) + + @client.query(<<-SQL) + INSERT INTO trilogy_test (time_test) + VALUES ("#{time.strftime("%H:%M:%S")}") + SQL + + results = @client.query(<<-SQL).to_a + SELECT time_test FROM trilogy_test + SQL + + assert_equal [[time]], results + + assert_kind_of Time, results[0][0] + end + def test_timestamp_cast_defaults_to_utc @client.query(<<-SQL) INSERT INTO trilogy_test (null_test)