'ArgumentError: bad value for range' for range of Times

Hi,

When using the calendar_date_select plugin, Rails kept throwing an
ArgumentError: 'bad value for range', but only on Windows (fine on
OSX). Playing around in the console I get...

38.years.ago..10.years.ago

=> Tue Jun 23 19:12:11 +1000 1970..Tue Jun 23 19:12:11 +1000 1998

39.years.ago..10.years.ago

=> ArgumentError: bad value for range

Any ideas?

Thanks

Hi,

When using the calendar_date_select plugin, Rails kept throwing an
ArgumentError: 'bad value for range', but only on Windows (fine on
OSX). Playing around in the console I get...

38.years.ago..10.years.ago

=> Tue Jun 23 19:12:11 +1000 1970..Tue Jun 23 19:12:11 +1000 1998

39.years.ago..10.years.ago

=> ArgumentError: bad value for range

Time only covers a reasonably small range. On OS X, the smallest time
representable is 1st January 1901, but I'm guessing that on windows
it's 1st jan 1970. DateTime is a native ruby thing that can represent
pretty much any date, and xxx.years.ago will fallback to that if
necessary. What I'm guessing is happening is that 39.years.ago..
10.years.ago will wind up trying to create a range where one endpoint
is an instance of DateTime and the other is a Time, which ruby doesn't
like. If that's the case then forcing both ends to instances of
DateTime (to_datetime) should do the trick.

Fred

Thanks, Fred. Much appreciated.