Skip to content
Open
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
1 change: 1 addition & 0 deletions lang/ruby/lib/avro/logical_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lang/ruby/test/test_logical_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down