@@ -37,10 +37,10 @@ def test_return_type_setter
3737
3838 def test_return_type_setter_raises_error_for_unsupported_type
3939 sf = DuckDB ::ScalarFunction . new
40- time_type = DuckDB ::LogicalType . new ( 14 ) # DUCKDB_TYPE_TIME (unsupported)
40+ interval_type = DuckDB ::LogicalType . new ( 15 ) # DUCKDB_TYPE_INTERVAL (unsupported)
4141
4242 error = assert_raises ( DuckDB ::Error ) do
43- sf . return_type = time_type
43+ sf . return_type = interval_type
4444 end
4545
4646 assert_match ( /only.*supported/i , error . message )
@@ -291,5 +291,28 @@ def test_scalar_function_date_return_type # rubocop:disable Metrics/AbcSize, Met
291291 assert_equal Date . new ( 2024 , 1 , 16 ) , rows [ 0 ] [ 0 ]
292292 assert_equal Date . new ( 2024 , 12 , 26 ) , rows [ 1 ] [ 0 ]
293293 end
294+
295+ def test_scalar_function_time_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
296+ @con . execute ( 'SET threads=1' )
297+ @con . execute ( 'CREATE TABLE test_table (t TIME)' )
298+ @con . execute ( "INSERT INTO test_table VALUES ('10:30:00'), ('23:59:59')" )
299+
300+ sf = DuckDB ::ScalarFunction . new
301+ sf . name = 'add_one_hour'
302+ sf . add_parameter ( DuckDB ::LogicalType . new ( 14 ) ) # TIME (type ID 14)
303+ sf . return_type = DuckDB ::LogicalType . new ( 14 ) # TIME
304+ sf . set_function { |time | time + 3600 } # Add 1 hour (3600 seconds)
305+
306+ @con . register_scalar_function ( sf )
307+ result = @con . execute ( 'SELECT add_one_hour(t) FROM test_table ORDER BY t' )
308+ rows = result . to_a
309+
310+ assert_equal 2 , rows . size
311+ # TIME values are returned as Time objects with today's date
312+ assert_equal 11 , rows [ 0 ] [ 0 ] . hour
313+ assert_equal 30 , rows [ 0 ] [ 0 ] . min
314+ assert_equal 0 , rows [ 1 ] [ 0 ] . hour
315+ assert_equal 59 , rows [ 1 ] [ 0 ] . min
316+ end
294317 end
295318end
0 commit comments