Skip to content

Commit

Permalink
Fix casting of the time type
Browse files Browse the repository at this point in the history
A time of 00:00:00 is perfectly valid, so we should not cast that to a
nil. That results in incorrect values.
  • Loading branch information
dbussink committed Jul 6, 2023
1 parent 93038bc commit 17aa087
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 0 additions & 4 deletions contrib/ruby/ext/trilogy-ruby/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
17 changes: 17 additions & 0 deletions contrib/ruby/test/cast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 17aa087

Please sign in to comment.