mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/date] Support -Float::INFINITY...date ranges
Fixes Ruby Bug 12961
7f533c2552
This commit is contained in:
parent
4e40ca301c
commit
fc0e8d00bc
2 changed files with 17 additions and 0 deletions
|
@ -5,6 +5,10 @@ require 'date_core'
|
||||||
|
|
||||||
class Date
|
class Date
|
||||||
|
|
||||||
|
def infinite?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
class Infinity < Numeric # :nodoc:
|
class Infinity < Numeric # :nodoc:
|
||||||
|
|
||||||
include Comparable
|
include Comparable
|
||||||
|
|
|
@ -6,6 +6,19 @@ class DateSub < Date; end
|
||||||
class DateTimeSub < DateTime; end
|
class DateTimeSub < DateTime; end
|
||||||
|
|
||||||
class TestDate < Test::Unit::TestCase
|
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
|
def test__const
|
||||||
assert_nil(Date::MONTHNAMES[0])
|
assert_nil(Date::MONTHNAMES[0])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue