diff --git a/lang/ruby/lib/avro/logical_types.rb b/lang/ruby/lib/avro/logical_types.rb index 48e0ded5098..479c119c89f 100644 --- a/lang/ruby/lib/avro/logical_types.rb +++ b/lang/ruby/lib/avro/logical_types.rb @@ -205,6 +205,7 @@ module IntDate def self.encode(date) return date.to_i if date.is_a?(Numeric) + date = Date.parse(date) if date.is_a?(String) (date - EPOCH_START).to_i end diff --git a/lang/ruby/test/test_logical_types.rb b/lang/ruby/test/test_logical_types.rb index 5d5d5b80f24..648abea1e12 100644 --- a/lang/ruby/test/test_logical_types.rb +++ b/lang/ruby/test/test_logical_types.rb @@ -38,6 +38,9 @@ def test_int_date_conversion assert_equal 0, type.encode(Date.new(1970, 1, 1)) assert_equal(-5, type.encode(Date.new(1969, 12, 27))) + assert_equal 5, type.encode('1970-01-06') + assert_equal 0, type.encode('1970-01-01') + assert_equal Date.new(1970, 1, 6), type.decode(5) assert_equal Date.new(1970, 1, 1), type.decode(0) assert_equal Date.new(1969, 12, 27), type.decode(-5)