Bug #6864

bad value for range when using infinity with date or time

Added by Alex Grebennik over 1 year ago. Updated over 1 year ago.

[ruby-core:47160]
Status:Assigned
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:-
Target version:next minor
ruby -v:ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] Backport:

Description

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.

History

#1 Updated by Alex Grebennik over 1 year ago

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

#2 Updated by Yusuke Endoh over 1 year ago

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

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 over 1 year ago

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

#4 Updated by Yusuke Endoh over 1 year ago

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

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