I am using the Range class to represent a range of times. Now I want a range which represents any point after a given time.
I tried (DateTime.now .. nil)
It's possible using DateTime::Infinity
class:
future = DateTime.now..DateTime::Infinity.new
future.include?(1_000_000.years.from_now) #=> true
When you need to represent infinite time, you could use an object from a different class, that you create yourself. Just implement the matching operator and any other methods you use, and then it can be used interchangeably with Range objects.
class TimeRange
def initialize(min, max)
...
end
end
range = (Time.now.to_f .. Float::INFINITY)
range.include?(Time.now.to_f) # => true
sleep 1
range.include?(Time.now.to_f) # => true
range.include?(Float::INFINITY) # => true