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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source 'https://rubygems.org'
gemspec unless RUBY_ENGINE == 'jruby'

group :development do
gem "bigdecimal"
gem "bundler"
gem "rake"
gem "rake-compiler"
Expand Down
2 changes: 1 addition & 1 deletion ext/date/date_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6920,7 +6920,7 @@ cmp_gen(VALUE self, VALUE other)
get_d1(self);

if (k_numeric_p(other))
return INT2FIX(f_cmp(m_ajd(dat), other));
return rb_funcallv(m_ajd(dat), id_cmp, 1, &other);
else if (k_date_p(other))
return INT2FIX(f_cmp(m_ajd(dat), f_ajd(other)));
return rb_num_coerce_cmp(self, other, id_cmp);
Expand Down
15 changes: 15 additions & 0 deletions test/date/test_date_arith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ def test__compare
DateTime.new(2001,1,17,0,0,0,0,Date::GREGORIAN)))
end

def test__compare_nan
nans = [Float::NAN]
begin
require "bigdecimal"
nans << BigDecimal("NaN")
rescue LoadError
end
d = Date.new(2000,1,1)
nans.each do |nan|
assert_nil(d <=> nan)
assert_equal(false, d == nan)
assert_raise(ArgumentError) { d < nan }
end
end

def test_prev
d = Date.new(2000,1,1)
assert_raise(NoMethodError) do
Expand Down