Bug #6864

bad value for range when using infinity with date or time

Added by Alex Grebennik over 3 years ago. Updated about 3 years ago.

Assignee:Yukihiro Matsumoto
ruby -v:ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] Backport:


Steps to reproduce:

require 'date'
Range.new(Date.today, 1.0/0.0) # works
Range.new(-1.0/0.0, Date.today) # fails
Range.new(Time.now, 1.0/0.0) # fails
Range.new(-1.0/0.0, Time.now) # fails

Tested on 1.9.3 and trunk. I think this is a bug, because there is no logic error. just ranges without one bound.


#1 Updated by Alex Grebennik over 3 years ago

And sometimes range behavior cant be understood - Range.new(Date.new(0), BigDecimal.new(9))

#2 Updated by Yusuke Endoh about 3 years ago

  • Status changed from Open to Assigned
  • Target version set to 2.0.0
  • Assignee set to tadayoshi funaba

This is caused by the following behavior.

p Date.today <=> 1.0 #=> 1
p 1.0 <=> Date.today #=> nil

Funaba-san, what do you think?
It may be good to provide Date#coerce.

Yusuke Endoh mame@tsg.ne.jp

#3 Updated by tadayoshi funaba about 3 years ago

this asymmetry is intentional.
i don't want to accept aNum + aDate.
Range's spec is variable.

#4 Updated by Yusuke Endoh about 3 years ago

  • Target version changed from 2.0.0 to next minor
  • Assignee changed from tadayoshi funaba to Yukihiro Matsumoto

I see, thank you. Then, addressing this issue requires
changing Range's spec, which is too heavy from this time.
I postpone this to next minor.

Yusuke Endoh mame@tsg.ne.jp

Also available in: Atom PDF