From 865962340e8252150e3d7a49f5e7c59de9ddd199 Mon Sep 17 00:00:00 2001 From: abMatGit Date: Thu, 5 Mar 2026 12:20:26 -0800 Subject: [PATCH] Add Date parsing to handle ISO8601 formatted dates --- lang/ruby/lib/avro/logical_types.rb | 1 + lang/ruby/test/test_logical_types.rb | 3 +++ 2 files changed, 4 insertions(+) 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)