Bug #17169
closedBad value for range using infinity for Time
Description
How to reproduce:
-Float::INFINITY...Float::INFINITY # works
Date.today...Float::INFINITY # works
-Float::INFINITY...Date.today # works
Time.now...Float::INFINITY #fails with "ArgumentError: bad value for range"
-Float::INFINITY...Time.now #fails with "ArgumentError: bad value for range"
I don't see why there should be a difference in this respect between Date and Time
This is issue is related to https://bugs.ruby-lang.org/issues/12961 which is Closed but actually only fixed the Date case.
P.S.: The Time.now...Float::INFINITY works with Rails' ActiveSupport via Time monkey-patching. However, monkey patching Float feels riskier.
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Status changed from Open to Rejected
@matz (Yukihiro Matsumoto) already rejected enhancing Time ranges in https://bugs.ruby-lang.org/issues/12961#note-5: So we only need to fix Date class. I don't think we should enhance Time ranges to support Integer/Float.
So the current behavior is not a bug. If you would like, we could switch this issue to a feature request, but considering it has already been rejected recently, I think it is unlikely to be accepted.
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
Probably, since ruby 2.7, you can use begin-less/end-less ranges instead.