Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casting of the time type #97

Merged
merged 1 commit into from
Jul 7, 2023
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
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