I'm struggling to define a date range in Ruby (2.6.3) that represents the range of dates up to a given date (in my examples it is Date.today):
BigDecimal("Infinity")...Date.today
*** ArgumentError Exception: bad value for range
nil...Date.today
*** ArgumentError Exception: bad value for range
Date::Infinity.new...Date.today
*** ArgumentError Exception: bad value for range
(Date.today...-Date::Infinity.new)
Fri, 31 May 2019...#
this one doesn't break, but also doesn't appear to give me a meaningful date range:
(Date.today...-Date::Infinity.new).include? Date.yesterday
false
As of ruby 2.7, this is no longer an issue, infinite ranges are handled gracefully:
(..Date.today).cover?(100.years.ago)
=> true
(nil..Date.today).cover?(100.years.ago)
=> true
Maybe not the best solution, but it can be helpful:
(-Float::INFINITY...Date.today.to_time.to_i).include? Date.yesterday.to_time.to_i
=> true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With