Hi all, I am building an applications that access an existing database that has dates in the future...as far ahead as 2106. However, when I try to access the data in those columns (I'm using the OCI8 driver), I get the following error: RangeError in Tools#search out of range of Time (expect between 1970-01-01 00:00:00 UTC and 2037-12-31 23:59:59, but 2106-02-22 15:17:54 EST) Anyone familiar with this? How can I resolve?
on 2006-02-28 18:13
on 2006-03-01 04:51
On Feb 28, 2006, at 8:11 AM, Carlos Diaz wrote: > Anyone familiar with this? How can I resolve? Either Use Date instead of Time. Or Upgrade to an OS (and possibly machine) with a 64-bit time_t: $ ruby -v -rtime -e 'p Time.parse("2106-02-22 15:17:54 EST")' ruby 1.8.4 (2005-12-24) [amd64-freebsd6] Mon Feb 22 12:17:54 PST 2106 Note that FreeBSD on x86 has a 32 bit time_t: $ ruby -v -rtime -e 'p Time.parse("2106-02-22 15:17:54 EST")' ruby 1.8.2 (2004-12-25) [i386-freebsd5] /usr/local/lib/ruby/1.8/time.rb:162:in `utc': time out of range (ArgumentError) from /usr/local/lib/ruby/1.8/time.rb:162:in `parse' from -e:1 -- Eric H. - firstname.lastname@example.org - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com
on 2006-03-01 05:05
Ok, after doing some research on this, it looks like the problem isn't with OCI8 but it appears to be more directly related to a conversion problem. Specifically when oci8.rb tries to covert the Oracle Date into Time.local. This is because Time relies on seconds since 1970 and I think the 32 bit operating system does not have enough room to store a date with that many seconds since 1970 (please correct me if I'm wrong). For example, if I go to irb and type: Time.local(2106, 02, 22, 15, 17, 54), that should produce th date below, but it actually give me a ArgumentError: time out of range. Has anyone else found a way to work around this problem? I found the following link where Kirk H. seemed to think this was not a difficult fix. Just don't know if anyone has gotten around to writing it: http://groups.google.com/group/comp.lang.ruby/brow... Any help would be greatly appreciated. Thanks, Carlos
on 2006-03-01 16:29
> Any help would be greatly appreciated. > > Thanks, > Carlos I am sure this is bad, evil, probably wrong as hell thing to to but: I am using a simple simple program that suffers from this problem. I only wanted the Date values, I didn't care about the time value as it was always 00:00. I cannot change the table structure and I am not actively using the value (I am going from oracle to a RoR view with <%= class.date %>, no processing) I browsed around for ages and found someone talking about messing with the oci8.rb file OraDate function. I changed class OraDate def to_time begin Time.local(year, month, day, hour, minute, second) rescue ArgumentError msg = format("out of range of Time (expect between 1970-01-01 00:00:00 UTC and 2037-12-31 23:59:59, but %04d-%02d-%02d %02d:%02d:%02d %s)", year, month, day, hour, minute, second, Time.at(0).zone) raise RangeError.new(msg) end end To class OraDate def to_time begin Time.local(year, month, day, hour, minute, second) rescue ArgumentError Date.new(year, month, day) end end So I guess I am in essence saying "If to_time fails, use to_date"... It worked for me in a trivial application and I am sure I have condemned myself to hell for using it so be careful. I have no idea what hte ramifications are and how it would cope in a more complex program. It might cost you your soul ;) Jeff
on 2006-03-01 17:00
Hi, "Carlos Diaz" <email@example.com> writes: > 2037-12-31 23:59:59, but 2106-02-22 15:17:54 EST) > > Anyone familiar with this? How can I resolve? Did you use OraDate#to_time? How about OraDate#to_date or OraDate#to_datetime?