Skip to content

Commit

Permalink
Support -Float::INFINITY...date ranges
Browse files Browse the repository at this point in the history
Fixes Ruby Bug 12961
  • Loading branch information
jeremyevans committed Oct 18, 2019
1 parent a2f4b66 commit 7f533c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/date.rb
Expand Up @@ -5,6 +5,10 @@

class Date

def infinite?
false
end

class Infinity < Numeric # :nodoc:

include Comparable
Expand Down
13 changes: 13 additions & 0 deletions test/date/test_date.rb
Expand Up @@ -6,6 +6,19 @@ class DateSub < Date; end
class DateTimeSub < DateTime; end

class TestDate < Test::Unit::TestCase
def test_range_infinite_float
today = Date.today
r = today...Float::INFINITY
assert_equal today, r.begin
assert_equal Float::INFINITY, r.end
assert_equal true, r.cover?(today+1)
assert_equal false, r.cover?(today-1)
r = (-Float::INFINITY)...today
assert_equal(-Float::INFINITY, r.begin)
assert_equal today, r.end
assert_equal false, r.cover?(today+1)
assert_equal true, r.cover?(today-1)
end

def test__const
assert_nil(Date::MONTHNAMES[0])
Expand Down

0 comments on commit 7f533c2

Please sign in to comment.