From bff566fc93ffa2aa027cdd9aeccefdf25908e4b6 Mon Sep 17 00:00:00 2001 From: Yifan Chen <30335308+emecii@users.noreply.github.com> Date: Wed, 9 Sep 2026 21:36:37 -0700 Subject: [PATCH 1/2] GH-51271: [Ruby] Fix Date values in ArrowFormat::Date32Array --- ruby/red-arrow-format/lib/arrow-format/array.rb | 3 ++- ruby/red-arrow-format/test/test-array-builder.rb | 5 +++-- ruby/red-arrow-format/test/test-date32-array.rb | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ruby/red-arrow-format/lib/arrow-format/array.rb b/ruby/red-arrow-format/lib/arrow-format/array.rb index 20929493e906..8bf7393fd960 100644 --- a/ruby/red-arrow-format/lib/arrow-format/array.rb +++ b/ruby/red-arrow-format/lib/arrow-format/array.rb @@ -489,11 +489,12 @@ def type end private + UNIX_EPOCH = 2440588 def pack_value(value, template, type) if value.nil? [0].pack(template) elsif value.is_a?(Date) - [value.day].pack(template) + [value.jd - UNIX_EPOCH].pack(template) else [value].pack(template) end diff --git a/ruby/red-arrow-format/test/test-array-builder.rb b/ruby/red-arrow-format/test/test-array-builder.rb index bae8e88c029b..f2e6a70fc55c 100644 --- a/ruby/red-arrow-format/test/test-array-builder.rb +++ b/ruby/red-arrow-format/test/test-array-builder.rb @@ -144,7 +144,8 @@ def test_time def test_date values = [Date.new(2026, 7, 17)] - assert_equal(ArrowFormat::Date32Array.new(values), - ArrowFormat::Array.build(values)) + array = ArrowFormat::Array.build(values) + assert_equal(ArrowFormat::Date32Array, array.class) + assert_equal([20651], array.to_a) end end diff --git a/ruby/red-arrow-format/test/test-date32-array.rb b/ruby/red-arrow-format/test/test-date32-array.rb index 331daabd833a..2d9a22c4c9b3 100644 --- a/ruby/red-arrow-format/test/test-date32-array.rb +++ b/ruby/red-arrow-format/test/test-date32-array.rb @@ -35,6 +35,18 @@ def test_mixed assert_equal(values, ArrowFormat::Date32Array.new(values).to_a) end + + def test_date + values = [ + Date.new(1969, 12, 31), + Date.new(1970, 1, 1), + nil, + Date.new(2025, 12, 9), + ] + expected = [-1, 0, nil, @date_2025_12_09] + assert_equal(expected, + ArrowFormat::Date32Array.new(values).to_a) + end end sub_test_case("#==") do From b848efba5128c457619f0abad4bb9eddf7488060 Mon Sep 17 00:00:00 2001 From: Yifan Chen <30335308+emecii@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:55:04 -0700 Subject: [PATCH 2/2] GH-51271: Address Date32 review feedback --- ruby/red-arrow-format/lib/arrow-format/array.rb | 3 ++- ruby/red-arrow-format/test/test-array-builder.rb | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby/red-arrow-format/lib/arrow-format/array.rb b/ruby/red-arrow-format/lib/arrow-format/array.rb index 8bf7393fd960..90a3be41ce9d 100644 --- a/ruby/red-arrow-format/lib/arrow-format/array.rb +++ b/ruby/red-arrow-format/lib/arrow-format/array.rb @@ -16,6 +16,7 @@ # under the License. require "bigdecimal" +require "date" require_relative "array-builder" require_relative "bitmap" @@ -489,7 +490,7 @@ def type end private - UNIX_EPOCH = 2440588 + UNIX_EPOCH = Date.new(1970, 1, 1).jd def pack_value(value, template, type) if value.nil? [0].pack(template) diff --git a/ruby/red-arrow-format/test/test-array-builder.rb b/ruby/red-arrow-format/test/test-array-builder.rb index f2e6a70fc55c..bae8e88c029b 100644 --- a/ruby/red-arrow-format/test/test-array-builder.rb +++ b/ruby/red-arrow-format/test/test-array-builder.rb @@ -144,8 +144,7 @@ def test_time def test_date values = [Date.new(2026, 7, 17)] - array = ArrowFormat::Array.build(values) - assert_equal(ArrowFormat::Date32Array, array.class) - assert_equal([20651], array.to_a) + assert_equal(ArrowFormat::Date32Array.new(values), + ArrowFormat::Array.build(values)) end end