GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
With activesupport-3.2.8, picking only the DateTime conversions:
1.9.3p327 :002 > require 'active_support/core_ext/date_time/conversions'
1.9.3p327 :003 > DateTime::Infinity.new..DateTime::Infinity.new
=> #<Date::Infinity:0x8465944 @d=1>..#<Date::Infinity:0x8465930 @d=1>
1.9.3p327 :004 > DateTime.new..DateTime::Infinity.new
ArgumentError: bad value for range
from /home/lars/.rvm/rubies/ruby-1.9.3-p327/bin/irb:16:in `<main>'
1.9.3p327 :001 > require 'active_support'
1.9.3p327 :002 > DateTime::Infinity.new..DateTime::Infinity.new
=> #<Date::Infinity:0x8e9d2e0 @d=1>..#<Date::Infinity:0x8e9d2b8 @d=1>
1.9.3p327 :003 > DateTime.new..DateTime::Infinity.new
=> #<DateTime: -4712-01-01T00:00:00+00:00 ((0j,0s,0n),+0s,2299161j)>..#<Date::Infinity:0x90c8f88 @d=1>
I think the reason for this is the DateTime#<=> method in lib/active_support/core_ext/date_time/calculations.rb. It should probably handle DateTime::Infinity instances differently, eg:
return -1 if other.kind_of?(Infinity)
Or it could delegate to super (Date#<=>) which handles DateTime::Infinity objects properly:
super other.kind_of?(Infinity) ? other : other.to_datetime
A third option would be to define DateTime::Infinity#to_datetime and have it return self, which should allow the default comparison to return -1 as expected, eg:
fwiw, I would happily submit a PR that fixes this bug if I could get some direction on which approach above I should take.
@dkubb it is already fixed on master in a more generic way by #7350, but I prefer to not backport it.
I think we can go with your second solution on 3-2-stable.
@rafaelfranca I opened a pull request that applies the fix you suggested. It also includes the tests from @gsphanikumar
Please ignore the previous PR, I mistakenly pointed it at rails/master.